mark60480 Posted March 9, 2013 Share Posted March 9, 2013 How do I code my php script to have the users e-mail address populate the "sent from" in the e-mail message. When the admin responds to the message by hitting "reply", it should go back to the user. Here is the line as it is now, which just puts a static "The web site" in the "sent from": mail($to_addr, $_REQUEST['subject'].' '.$_REQUEST['name'],$mail_body,'From: The web site>' . "\r\n"); I'm also attaching the entire script. THANKS! sendformContact_test.php Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/ Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 You should use the reply-to parameter, not the from. If you're capturing their email in the form, you'd use it just like you did subject and name. Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1417733 Share on other sites More sharing options...
davidannis Posted March 9, 2013 Share Posted March 9, 2013 You should make the from be from yourself as Jessica said so that you never have an issue with the SMTP accepting the message. Here's how: $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: ' .$_REQUEST['email'] "\r\n" mail($to_addr, $_REQUEST['subject'], $mail_body, $headers); the directions are here: http://php.net/manual/en/function.mail.php Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1417734 Share on other sites More sharing options...
mark60480 Posted March 9, 2013 Author Share Posted March 9, 2013 Ok, I guess you're assuming that I'm smarter than I really am. Jessica- I understand what your saying, but don't know how to code it. David- I pasted your code into my script, but got an error message: BTW, line 17 is the middle line of your script. Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /mywebsite.com/Scripts/sendform.php on line 17 BTW, line 17 is the middle line of your script. Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1417748 Share on other sites More sharing options...
davidannis Posted March 10, 2013 Share Posted March 10, 2013 oops, sorry. I left the semi-colon off of the end of that line. You also need to replace the 'email' in that line with the name of the field that is submitted in your form (I never looked) and the e-mail address in the line above with your e-mail address. Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1417824 Share on other sites More sharing options...
mark60480 Posted March 13, 2013 Author Share Posted March 13, 2013 OK. Sorry David, but it's still not working. Here's the entire script as it stands: <?php $to_addr = $_REQUEST['recipient']; $mail_body = "Message sent from from ".$_REQUEST['site']."\n. DO NOT USE REPLY!"; $mail_body .= "\n\nName: ".$_REQUEST['name']; $mail_body .= "\nE-Mail: ".$_REQUEST['email']; $mail_body .= "\n\nQuestion: ".stripslashes($_REQUEST['question']); print "<meta http-equiv=\"refresh\" content=\"0;url=/pages/contactThanks.html\">"; $headers = 'From: webmaster@example.com' . "\r\n" . 'Reply-To: ' .$_REQUEST['email'] "\r\n" ; mail($to_addr, $_REQUEST['subject'], $mail_body, $headers); ?> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1418429 Share on other sites More sharing options...
davidannis Posted March 13, 2013 Share Posted March 13, 2013 Can you comment out the refresh and see what is in $_REQUEST by adding print_r($_REQUEST); Do you know that your SMTP server on the local machine is working? David Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1418485 Share on other sites More sharing options...
mark60480 Posted March 19, 2013 Author Share Posted March 19, 2013 I am testing this on the web, not locally. Here is the error message I get when using the above script: Parse error: syntax error, unexpected in /Scripts/sendform.php on line 17 Line 17 is: 'Reply-To: ' .$_REQUEST['email'] "\r\n" ; I should point out again that my PHP knowledge is very limited. I inherited this script and modify it by trial and error (mostly error). Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1419579 Share on other sites More sharing options...
Solution davidannis Posted March 19, 2013 Solution Share Posted March 19, 2013 You need a . (period) between the email'] and the "\r Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1419594 Share on other sites More sharing options...
mark60480 Posted March 20, 2013 Author Share Posted March 20, 2013 That fixed it. Thanks so much David! Quote Link to comment https://forums.phpfreaks.com/topic/275441-email-address-from-form-submission-to-appear-in-from/#findComment-1419943 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.