Jump to content

email address from form submission to appear in "From"


mark60480
Go to solution Solved by davidannis,

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.