View Full Version : PHP form not sending to all email addresses?

01-25-2010, 03:30 AM
Hi guys,

I'm a real beginner here and I could really do with some advice!

I've created a (very simple) PHP form for my client and have tested it but entering my hotmail e-mail address to send the form to. This seems to work fine. When I enter my client's e-mail address however, the form seems to send, (and re-directs you to the 'thankyou' page) but my client is not recieving any emails?! (not even in their junk mail folder)

I have posted my code below if it helps. I'm a bit lost here and my client's e-mail provider are not too helpful.

Thanks in advance guys.

if(isset($_POST['submit'])) {

$subject = "Contact / Booking Form from booking Website";
$name = $_REQUEST['name'];
$email_field = $_POST['email'];

$phone = $_POST['phone'];
$comments = $_POST['comments'];

$headers = "From: $name via booking website";

$body = "From: $name \n\n E-Mail: $email_field\n\n Phone Number: $phone\n\n Message:\n $comments\n";

header( "Location: thankyou_contact.html" );
mail($to, $subject, $body, $headers);

} else {

echo "Unexpected error. Please contact your website host";


01-25-2010, 03:35 AM
Wrong email put in? maybe their email account doesn't accept mail()?

12-27-2011, 07:43 PM
The mail() function returns a boolean result.

Therefore you should be testing it like this:

if (mail(<parameters go here>))
print 'Mail sent';
print 'Not sent';

Secondly the header/location line should be AFTER the call to mail not before it.