View Full Version : Trouble with contact Form

10-25-2012, 05:46 PM
Hey Guys,

I've recently started learning PHP and am trying to code a simple contact form, the form looks right and acts how it is suppose to when you press submit however the information does not actually get sent.

Here's the php code


$recieverEmail = 'adam.cullen@live.co.uk';
$resultError = 'Sending Failed! Please fill in all forms!';
$resultSuccess = 'We have recieved your message, Thank You.';

$emailSubject = 'Message from Contact Form on Dot 2 Dot Website: ' .$subject;
$subject = $_POST["subject"];
$email = $_POST["email"];
$message = $_POST["message"];
$name = $_POST["name"];
$phone = $_POST["name"];

$mailHeader = "From: " . $email . "\r\n";
$mailHeader .= "Reply-To: " . $email . "\r\n";
$mailHeader .= "Content-type: text/html; charset=iso-8859-1\r\n";

$messageBody = "Message: <br/>" . nl2br($message) . "<br/>";
$messageBody .= "Name: " . $name . "<br/>";
$messageBody .= "Email: " . $email . "<br>";
$messageBody .= "Phone: " . $phone;

if( empty($subject) or empty($email) or empty($name) or empty($message) or empty($phone) ){
header('Location: index.php?result=' . $resultError );
} else {
mail($recieverEmail, $emailSubject, $messageBody, $mailHeader);
header('Location: index.php?result=' . $resultSuccess );


sorry if it's something simple

10-25-2012, 06:20 PM
You should check the return status of the mail() function. It may be telling you something that you're ignoring.


10-25-2012, 06:23 PM
Sorry for my ingnorance but how do i do that??

10-25-2012, 06:43 PM
if (!mail($recieverEmail, $emailSubject, $messageBody, $mailHeader))
echo "mail failed to send";


10-25-2012, 06:50 PM
Sorry but i don't understand what that does as all seems to do is add in the line "mail failed to send" into the form page.

10-25-2012, 07:18 PM
Ok, so that's telling you the mail function is unable to work (as opposed to it sending the mail, but it not getting there). I'd print out the values of the four parameters you're passing to mail(), and see if they contain what you expect.