Jump to content

PHP form works but I need the Users Name in the Header


ajwaldrop

Recommended Posts

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)

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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.