PHP to send email from contact web form not working - please help!

Hello,

I am new to php coding. I have a simple contact form on my web site and I uploaded a php document to send the content from my web form to my email. I also created a web page to display after submission - thanking the users for their email.

Well, the thank you page loads after submitting the form - however no email is ever received. I do not get any error messages. it acts as if it is working, but no email is ever received.

Below is my php code. What am I doing wrong? My site is hosted at justhost.com.

Thank you very much for your help!

code:

[php]<?php

/* Subject and Email Variables*/

$emailSubject = 'Email from Rex Miller Design Web site!';
$webMaster = '[email protected]';

/* Gathering Data Variables/*

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$purposeField = $_POST['purpose'];
$commentsField = $_POST['comments'];

$body = <<<EOD





Email: $email

Name: $name

Purpose: $purpose

Comments: $comments

EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results Rendered as HTML */

$theResults = <<<EOD
THANK YOU

Content on this page requires a newer version of Adobe Flash Player.

Get Adobe Flash player

 

Thank you!

 

Thank you for your email.

I will respond as soon as possible!

 

EOD;
echo “$theResults”;

?>
[/php]

Try to remove \r from headers, leave only \n
Then check the spam folder of your mailbox.

Also, I believe there is mistake in variable names in your code. You probably meant to have these names:
[php]$email = $_POST[‘email’];
$name = $_POST[‘name’];
$purpose = $_POST[‘purpose’];
$comments = $_POST[‘comments’];[/php]

And finally, you need to sanitize the $email string before generating $headers (particularly, check and remove any new lines \n, spaces etc. otherwise your mail form may be exploited by spammers)

Sponsor our Newsletter | Privacy Policy | Terms of Service