...

View Full Version : Trouble with contact Form



designer21
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




<?php

$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

tracknut
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.

Dave

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

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


Dave

designer21
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.

tracknut
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.

Dave



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum