Skip navigation
Currently Being Moderated

Problem with 'Reply-To' on PHP contact form...

May 4, 2013 2:18 AM

Tags: #php #form #reply-to

Hi guys,

 

I've created a PHP contact form which works perfectly; except, when I receive the email to my inbox and go to reply to it, it doesn't reply to the email address of the person who submitted the form - in the reply field it appears to have the default server email address.

 

Here's my code which I have included in the same PHP page as my form:

 

<?php

if (array_key_exists('submit', $_POST)) {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $formMessage = $_POST['message'];

if (empty($name)) {
$warning['name'] = "Please provide your name";
}

if (empty($email)) {
$warning['email'] = "Please provide your email address";
}

if (empty($formMessage)) {
$warning['message'] = "Please type your message";
}

$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$to = "me@myemail.com";
$subject = "Enquiry from website";

$message = $headers;
$message .= "Name: " . $_POST["name"] . "\r\n";
$message .= "E-mail: " . $_POST["email"] . "\r\n";

$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

$message= "

<table cellspacing='0' cellpadding='8' border='0' width='500'>
<tr>
<td colspan='2'></td>
</tr>
<tr bgcolor='#eeeeee'>
<td width='154' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'><strong>Name</strong></td>
<td width='314' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'>".$name."</td>
</tr>
<tr bgcolor='#eeeeee'>
<td style='font-family:Verdana, Arial; font-size:11px; color:#333333;'><strong>E-mail address:</strong></td>
<td style='font-family:Verdana, Arial; font-size:11px; color:#333333;'>".$email."</td>
</tr>
<tr bgcolor='#eeeeee'>
<td colspan='2' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'><strong>Message</strong></td>
</tr>
<tr bgcolor='#eeeeee'>
<td colspan='2' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'>".$formMessage."</td>
</tr>
<tr><td colspan='2' style='padding: 0px;'></td></tr>
</table>

";


$url = stripslashes($_POST["url"]);
if (!empty($url)) {
header( 'Location: http://www.go-away-spam-robots.com' );
exit();
}

if (!isset($warning)) {
mail($to, $subject, $message, $headers);
header( 'Location: http://www.mydomain.com/thankyou.php' ) ;
}

}

?>


 

Can anyone see from my code why this would be happening?

 

Thank you very much and hope to hear from you!

 

SM

 
Replies
  • Currently Being Moderated
    May 4, 2013 5:25 PM   in reply to Spindrift

    Thanks

     

    That is very considerate of you.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points