I am using a PHP mail form on my site. I receive mail just fine but the headers I am getting are in the form a7849972@srv29.000webhost.com, and the same for reply address. How can I change my code to get the person’s name in header? I am using the following code:
<?php
if(isset($_POST['submit'])) {
$to = 'chander_info@yahoo.com' ; //put your email address on which you want to receive the information
$subject = 'Message - Contact Form Coast Med Spa'; //set the subject of email.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$mailheader = "From: ".$_POST["FirstName"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$message = "<table>
<tr><td>Title</td><td>".$_POST['Title']."</td></tr>
<tr><td>First Name</td><td>".$_POST['FirstName']."</td></tr>
<tr><td>Last Name</td><td>".$_POST['LastName']."</td></tr>
<tr><td>E-Mail</td><td>".$_POST['Email']."</td></tr>
<tr><td>Phone Number</td><td>".$_POST['HomePhone']."</td></tr>
<tr><td>Comments</td><td>".$_POST['CAT_Custom_869']."</td></tr>
<tr><td>Contact Method</td><td>".$_POST['CAT_Custom_868']."</td></tr>
<tr><td>Subscribe to: eNewsletter</td> <td>".$_POST['CampaignList_41798']."</td></tr>
</table>" ;
mail($to, $subject, $message, $headers, $mailheader);
header('Location: http://coastlasercenter.com/html/message-contact.html');
echo "Your message has been received";
}
?>
Why are you separating headers into two different variables?
You’re passing the
FromandReply-toheaders as additional parameters to themail()function. Check PHP’s documentation.Try this:
BTW, you should consider validating the data you’re getting in $_POST before concatenating it to your email headers since it can lead to email injection attacks.