Are you having problems where your server’s information is showing in the “From” line and you want to show your customer’s email address (or the person who filled out your online form) instead? Your original code may look like this below…
Original code:
$name = stripslashes($_POST[‘name’]);
$email = trim($_POST[’email’]);
$subject = stripslashes($_POST[‘subject’]);
$message = stripslashes($_POST[‘message’]);
$phone = stripslashes($_POST[‘phone’]);
$answer = trim($_POST[‘answer’]);
$to=$toemail.’,’.$replyto;
$error = ”;
$headers=””;
$headers.=”Reply-to:$replyto\n”;
$headers .= “From: $email\n”;
$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers = “Content-Type: text/html; charset=iso-8859-1\n”.$headers;
Now revise your code to the following:
Revised Code:
$name = stripslashes($_POST[‘name’]);
$email = trim($_POST[’email’]);
$subject = stripslashes($_POST[‘subject’]);
$message = nl2br($_POST[‘message’]);
$phone = stripslashes($_POST[‘phone’]);
$answer = trim($_POST[‘answer’]);
$from=$email;
$to=$replyto;
$error = ”;
$headers= “From: $name $headers.= “Reply-to:” . $email . “\n”;
$headers .= ‘MIME-Version: 1.0’ . “\r\n”;
$headers = “Content-Type: text/html; charset=iso-8859-1\n”.$headers;
The items the were updated:
- $message in order to have the message text properly shown.
- Updated “From” line.
- Updated the “Reply-to” line in order to reply to the person who filled the contact form and not ourselves.
- Added a ”.” in the line of the MIME in order to send the mail with the mail of person who filled the contact form
I hope it helped people who use this awesome and easy script. If I made some mistakes in those modification don’t hesitate to correct me (I’m not a php dev.).