Forums

[resolved] PHP Mail Problem (3 posts)

  1. dipaksaraf
    Member
    Posted 1 year ago #

    I am using PHP mail functionality to send mail whenever a user submits the feedback on a post.

    The codes are something like this :
    <?php
    $headers = 'From: automated_message@somedomain.com'."\r\n" .
    'CC: abc@somedomain.com'."\r\n".
    'Reply-To:$_REQUEST['contactemail']'."\r\n";

    if ($_REQUEST['contactemail']){
    mail($to, 'Response to somedomain.com Ad', $body.$editlink,$headers);
    mail($_REQUEST['contactemail'], 'Response to somedomain.com Ad', $client_tag.$body, $headers);
    }else{
    echo'<h2>You seem to have entered an invalid e-mail address. Please try again.';
    }
    ?>

    When i am using email address in Reply-To: someeamilid@somedomain.com it works but when i use $_REQUEST['contactemail'] , it gives an error which is as follows: Parse error: syntax error, unexpected T_STRING in runtime.php(42):eval()’d code on line 24.

    LIne 24 is: $headers = 'From: automated_message@somedomain.com'."\r\n" .
    'CC: abc@somedomain.com'."\r\n".
    'Reply-To:$_REQUEST['contactemail']'."\r\n";

    Please suggest how o resolve this issue.

    Thanks
    Dipak

  2. Curtiss Grymala
    Member
    Posted 1 year ago #

    The $_REQUEST information is a PHP variable, but since you have it inside of single-quotes, it's being treated as a string. Then, the single-quote that wraps contactemail is actually exiting the quoted string, leaving contactemail as plain text outside of a string definition.

    So, PHP thinks you want to send a message to someone with the e-mail address of $_REQUEST[, then it sees contactemail right next to that and doesn't know what to do with it. Try this code instead:

    'Reply-To:' . $_REQUEST['contactemail'] ."\r\n";
  3. dipaksaraf
    Member
    Posted 1 year ago #

    Hello Curtis

    Thanks for the help, after changing the code as suggested, the mail is working smoothly.

    Thanks for the Help.......

    Dipak

Topic Closed

This topic has been closed to new replies.

About this Topic