simple contact form for my website
Posted: Wed Aug 19, 2009 6:41 am
Hi,
I am creating a simple contact form, below is my html code:
The PHP code is here:
I just need to know whether this works? I have uploaded it to my hosting provider and it doesn't seem to work. It needs to be tested server side? This way I can understand whether its a problem with my hosting provider or with my code? Please help!
ps just to let you know when a user fills in the form it always displays the error.html page...
I am creating a simple contact form, below is my html code:
Code: Select all
<form method="POST" action="contact.php">
<p style="margin-top: 0;">Fields marked (*) are required</p>
<p style="margin-top: 0;">Email From:* <br/>
<input type="text" name="EmailFrom">
<p style="margin-top: 0;">Name:* <br/>
<input type="text" name="Name">
<p style="margin-top: 0;">Address:<br/>
<input type="text" name="Address">
<p style="margin-top: 0;">Telephone:<br/>
<input type="text" name="Telephone">
<p style="margin-top: 0;">Message:*<br/>
<TEXTAREA NAME="Message" ROWS=6 COLS=40>
</TEXTAREA>
<p style="margin-top: 0;"><input type="submit" name="submit" value="Submit">
</form>
Code: Select all
<?php
//martin cooke
// get posted data into local variables
$EmailFrom = Trim(stripslashes($_POST['EmailFrom']));
$EmailTo = " contact@arldrainservices.co.uk";
$Subject = "Message to A R Lane Drain Services";
$Name = Trim(stripslashes($_POST['Name']));
$Address = Trim(stripslashes($_POST['Address']));
$Telephone = Trim(stripslashes($_POST['Telephone']));
$Message = Trim(stripslashes($_POST['Message']));
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $Address;
$Body .= "\n";
$Body .= "Telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, $Message, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
ps just to let you know when a user fills in the form it always displays the error.html page...