ajwaldrop Posted August 30, 2012 Share Posted August 30, 2012 Hello, I'm a newbie to php and having a trouble with an email form. It works but my client (the recipient of the mail form) wants to be able to drag and drop the email on a new contact in Outlook. The problem is it throws the email address into the "Name" Field. It also puts the email address in the email field (of course that part is good). It seems that I need the persons name to appear in the Header as part of From? But I don't know how to doe that. Any help would be greatly appreciated. Please see the code below. thanks!!! <?PHP header ('Location: http://billdurrence.com'); // You may have to add this code on some servers in order to work // $firstname = $_REQUEST["firstname"]; $lastname = $_REQUEST["lastname"]; $sender_email = $_REQUEST["email"]; $phone = $_REQUEST["phone"]; $address = $_REQUEST["address"]; $city = $_REQUEST["city"]; $state = $_REQUEST["state"]; $zip = $_REQUEST["zip"]; $comments = $_REQUEST["comments"]; // Change the email to the address where the mail should be sent to // $to = "awaldrop@longwater.com, $sender_email"; // Change the subject if you like // $subject = "From the Bill Durrence website"; $message = "First Name: " . $firstname; $message .= "\nLast Name: " . $lastname; $message .= "\nEmail: " . $sender_email; $message .= "\nPhone: " . $phone; $message .= "\nAddress: " . $address; $message .= "\nCity: " . $city; $message .= "\nState: " . $state; $message .= "\nZip: " . $zip; $message .= "\nComments: " . $comments; $message .= "\nIP Address: " . $_SERVER['REMOTE_ADDR']; $message .= "\nBrowser: " . $_SERVER['HTTP_USER_AGENT']; $headers = "First Name: $firstname"; $headers = "Last Name: $lastname"; $headers = "From: $sender_email"; $headers .= "\nReply-To: $sender_email"; $sentOk = mail($to,$subject,$message,$headers); echo "sentOk=" . $sentOk; //*******AUTO-RESPOND OPTIONS **************/ //This is the automatically generated email sent to the user, when the form is submitted // To change the From line, in the automatic response, change it in the first line below $auto_mail_headers = "From: bill@billdurrence.com\r\n"; $auto_mail_headers .= "Content-type: text/html\r\n"; //Here's the subject and the message contained in the automatically generated email $auto_subject = "Automated Message: Bill durrence Photography"; $auto_message = "Dear $firstname,<br /><br /> \r\n"; $auto_message .= "Thank you for submitting your comments. I have received your email and will get back with you soon! <br /><br /> -Sincerely,<br /> Bill Durrence\r\n"; mail ($sender_email, $auto_subject, $auto_message, $auto_mail_headers) ?> Quote Link to comment Share on other sites More sharing options...
Christian F. Posted August 30, 2012 Share Posted August 30, 2012 The format for that is quite clearly visible in any mailing client, namely: name with spaces <person@address.mail> Quote Link to comment Share on other sites More sharing options...
ajwaldrop Posted August 30, 2012 Author Share Posted August 30, 2012 I wasn't clear. I want the website vistor to fill out the html form. It process through the php above. Then when it arrives to the recipient it will have the visitors first and last name in the header along with the email address. thanks, Anthony Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 30, 2012 Share Posted August 30, 2012 See example #4 in the php manual, here: mail. Otherwise, explain how you're defining "in the header". Quote Link to comment Share on other sites More sharing options...
ajwaldrop Posted August 30, 2012 Author Share Posted August 30, 2012 Ok I guess my reference to the header is wrong. Basically I want the recipient to see the visitors name in the from. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2012 Share Posted August 30, 2012 name with spaces <person@address.mail> Quote Link to comment Share on other sites More sharing options...
ajwaldrop Posted August 30, 2012 Author Share Posted August 30, 2012 Thanks. I finally got it to work. Thanks everyone for the help! This solved it... $headers = "From: $firstname $lastname <$sender_email>"; Quote Link to comment Share on other sites More sharing options...
DavidAM Posted August 30, 2012 Share Posted August 30, 2012 You need to be aware that this is not the correct way to send mail. Your mail server at (say) MyDomain.com does not technically have the authority to send mail from the visitor's address at (say) HisDomain.com. In other words, specifying the visitor's email address in the FROM: header may cause problems. --- The mail is not from the visitor, it is from your website. Some mail servers will see it as an attempt to forge an email and refuse to send it. Some mail servers will see it as a forged email and refuse to deliver it, or put it in the Junk/Spam folder. The "correct" way to send email is to use the website's email address (something at MyDomain.com) in the FROM header and put the visitor's address in the REPLY-TO header. This may break your client's ability to "drop" it on a new contact record, I have never tried to do that. However, you need to keep this in mind since moving to a different web host or upgrading the mail server or changing/upgrading the spam filter software may cause the emails to stop being sent/delivered. Quote Link to comment Share on other sites More sharing options...
ajwaldrop Posted August 30, 2012 Author Share Posted August 30, 2012 Yes, totally aware of that but the client is always right. Thats what he wanted. Clicking the email in the body was too much trouble for some reason. He wanted to hit reply and be able to drag the email into his contacts for Outlook. Which is pretty handing when building a mailing list. Quote Link to comment Share on other sites More sharing options...
Jessica Posted August 30, 2012 Share Posted August 30, 2012 Yes, totally aware of that but the client is always right. Thats what he wanted. Clicking the email in the body was too much trouble for some reason. He wanted to hit reply and be able to drag the email into his contacts for Outlook. Which is pretty handing when building a mailing list. And sadly, his developer has never heard of Reply-To. Quote Link to comment Share on other sites More sharing options...
ajwaldrop Posted August 30, 2012 Author Share Posted August 30, 2012 I'll be the first to admit I'm not a developer. I'm a designer. However like I said he wanted to be able to drag and drop the email from the visitor onto his Outlook contacts as well. In that situation the Reply-To did not work for it would not show up in the address field. Thanks for the input Quote Link to comment Share on other sites More sharing options...
DavidAM Posted August 30, 2012 Share Posted August 30, 2012 ... he wanted to be able to drag and drop the email from the visitor onto his Outlook contacts ... You might want to consider building a VCard from the data you collected and attaching it to the email. He would have to open the email and import the VCard, but it would give him all of the information from the form instead of just the name and email address. That additional data along with the knowledge of the potential pitfalls (from my previous post) might make it worth the effort to him of opening the email (one extra click). I'll admit I have never done this, and I am not sure how involved it would be, but I do know that the Vcard is just a text file and a multi-part MIME message is not that difficult to build. BEGIN:VCARD VERSION:2.1 N:Mxxxxxx;David FN:David Mxxxxxx ORG:My Company Name TITLE:Operations Manager TEL;WORK;VOICE;PREF=1:(832) xxx-xxxx TEL;WORK;VOICE:(936) xxx-xxxx TEL;CELL;VOICE:(281) xxx-xxxx TEL;WORK;FAX:(832) xxx-xxxx ADR;WORK:;;9016 Our Street;SomeTown;TX;773xx;United States of America LABEL;WORK;ENCODING=QUOTED-PRINTABLE:9016 OurStreet=0D=0ASomeTown, TX 773xx=0D=0AUnited States of America URL;WORK:http://www.ourdomain.com EMAIL;PREF;INTERNET:David.Mxxxxxx@ourdomain.com REV:20110920T181435Z END:VCARD To get the VCard template, fill out a Contact record the way you want it, then select File->Save As ... (and choose the VCard filetype) or File->Export to vcard file .... You can open the file in any text editor and see the format. I did this when building the QR code for our business cards (well, I did some Googling, too). Quote Link to comment 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.