Ateu Posted May 15, 2010 Share Posted May 15, 2010 Hello world. I have a little script here to harness the data posted by the user on the HTML page and send it to the PHP script. The script will then send 1 e-mail to the guest and 1 e-mail to my staff, however, the e-mail that the guest gets has '[email protected]' in the from field when it should have 'Town and Country Hotels'. In other words, it's displaying an e-mail address when I want it to display a name. Below is my code (I have excluded the non-necessary parts for simplicity): <?php // Retrieve posted data and turn into local variables $OUREMAIL = 'Town and Country Hotels <[email protected]>'; $EMAIL = Trim(stripslashes($_POST['EMAIL'])); $NAME = Trim(stripslashes($_POST['NAME'])); $EmailTo = "[email protected]"; $EmailToWebmaster = "[email protected]"; $EmailTo2 = $EMAIL; $Subject = "Town and Country Hotels Online Form Submission"; $Subject2 = '' . $NAME . ', your message has been received!'; // validation $validationOK=true; if (Trim($EMAIL)=="") $validationOK=false; if (Trim($NAME)=="") $validationOK=false; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // Body of e-mail to staff has been excluded in the forum post // Body of e-mail to guest $Body2 .= ""; $Body2 .= "Dear "; $Body2 .= $NAME; $Body2 .= ","; $Body2 .= "\n"; $Body2 .= "\n"; $Body2 .= "Thank you for your message! A representative will be with you shortly, answering all your queries about Amamzintaba Resort. If you require an answer as a matter of urgancy, please call the hotel manager on 0027 824 529 015. Below is a copy of your message:"; $Body2 .= "\n"; $Body2 .= "\n"; $Body2 .= "Name: "; $Body2 .= $NAME; $Body2 .= "\n"; $Body2 .= "E-mail address: "; $Body2 .= $EMAIL; $Body2 .= "\n"; $Body2 .= "Telephone number (if given): "; $Body2 .= $TELEPHONE; $Body2 .= "\n"; $Body2 .= "Topic of question: "; $Body2 .= $TOPIC; $Body2 .= "\n"; $Body2 .= "Question: "; $Body2 .= $QUESTION; $Body2 .= "\n"; $Body2 .= "\n"; $Body2 .= "----"; $Body2 .= "\n"; $Body2 .= "This message was sent to "; $Body2 .= $EMAIL; $Body2 .= " and confirms the receipt of your message submitted via the Town and Country Hotels online contact form. Information submitted through this form is reatined for customer service improvement purposes and will never be rented, sold or distributed to a tertiary party whatsoever. This has been laid out in the privacy policy viewable at http://www.townandcountryhotels.net/legal.php#privacypolicy."; $Body2 .= "\n"; $Body2 .= "\n"; $Body2 .= "This is an unmonitored mailbox. Replies will be discarded."; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EMAIL>"); $success = mail($EmailToWebmaster, $Subject, $Body, "From: <$EMAIL>"); $success = mail($EmailTo2, $Subject2, $Body2, "From: <$OUREMAIL>"); // Redirect the guest to the success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=msgsent.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> If you visit my site (http://www.townandcountryhotels.net/contact.php) you'll see what I mean when you send a message. All advice is very much appreciated. Link to comment https://forums.phpfreaks.com/topic/201894-php-mail-show-sender-name/ Share on other sites More sharing options...
Jiin Posted May 15, 2010 Share Posted May 15, 2010 Hi Ateu, It seems like these are the relevant parts of your question?: "the e-mail that the guest gets has '[email protected]' in the from field when it should have 'Town and Country Hotels'. In other words, it's displaying an e-mail address when I want it to display a name." $OUREMAIL = 'Town and Country Hotels <[email protected]>'; $success = mail($EmailTo2, $Subject2, $Body2, "From: <$OUREMAIL>"); What happens if you change your OUREMAIL variable like this: $OUREMAIL = 'Town and Country Hotels'; Link to comment https://forums.phpfreaks.com/topic/201894-php-mail-show-sender-name/#findComment-1058946 Share on other sites More sharing options...
Ateu Posted May 16, 2010 Author Share Posted May 16, 2010 Thanks Jiin, but I've just got it working by talking out the "From: " and replacing it with 2 variables: $fromname = "Put your name here"; and $OUREMAIL = "Put your e-mail address here"; Then we have a 3rd variable called $HEADERS and it is made up of the 2 previous variables. Here is the finished code: $success = mail($EmailTo2, $Subject2, $Body2, $headers); Thanks for your suggestion anyway. Link to comment https://forums.phpfreaks.com/topic/201894-php-mail-show-sender-name/#findComment-1059036 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.