Help with PHP contact form!
Posted: Wed Jun 24, 2009 3:32 pm
All,
I am a PHP newbie but have tried everything humanly possible to get my PHP contact form to work and it still will not send an email. I would love some help as I'm trying to finish up a project.
Currently my PHP file resides in the same directory as the HTML file.
The HTML
The PHP
I am a PHP newbie but have tried everything humanly possible to get my PHP contact form to work and it still will not send an email. I would love some help as I'm trying to finish up a project.
Currently my PHP file resides in the same directory as the HTML file.
The HTML
Code: Select all
<form method="POST" action="contact.php">
<p>*All fields are required</p>
<p>Email: <br>
<input type="text" name="Email">
<p>Full name: <br>
<input type="text" name="Fullname">
<p>Address:<br>
<input type="text" name="Address1">
<p>City, State Zip:<br>
<input type="text" name="Address2">
<p>Telephone:<br>
<input type="text" name="Telephone">
<p>Best time for us to reach you:<br>
<input type="text" name="Time">
<p>Tel:<br>
<input type="text" name="Tel">
<p><input type="submit" name="submit" value="Submit">
</form>
Code: Select all
<?php
$EmailFrom = Trim(stripslashes($_POST['Email']));
$EmailTo = "christian.tate@gmail.com";
$Subject = Trim(stripslashes($_POST['Fullname']));
$Name = Trim(stripslashes($_POST['Address1']));
$Address = Trim(stripslashes($_POST['Address2']));
$City = Trim(stripslashes($_POST['Telephone']));
$State = Trim(stripslashes($_POST['Time']));
$Tel = Trim(stripslashes($_POST['Tel']));
// validation
$validationOK=true;
if (Trim($Email)=="") $validationOK=false;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Fullname;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address1;
$Body .= "\n";
$Body .= "City, State Zip: ";
$Body .= $Address2;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Best time to contact: ";
$Body .= $Time;
$Body .= "\n";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>