Page 1 of 1

simple contact form for my website

Posted: Wed Aug 19, 2009 6:41 am
by phpPain
Hi,

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>
 
 
 
The PHP code is here:

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\">";
}
?>
 
 
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...

Re: simple contact form for my website

Posted: Wed Aug 19, 2009 7:28 am
by mrvijayakumar
Hi phpPain,
This problem arises on contact.php file. I modified your code and adding correct code below,

Note: If u not receiving a mail means disable the following line "$headers .= 'From: <$EmailFrom>' . "\r\n";".

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']));
 
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; 
$headers .= 'From: <$EmailFrom>' . "\r\n";
 
$Message = "
Name:$Name 
Address: $Address 
Telephone: $Telephone 
$Message";
 
// send email
$success = mail($EmailTo, $Subject, $Message, $headers);
 
// 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\">";
}
?>

Re: simple contact form for my website

Posted: Wed Aug 19, 2009 7:38 am
by phpPain
Excellent, it now works, thankyou very much. :D

Re: simple contact form for my website

Posted: Wed Aug 19, 2009 7:39 am
by mrvijayakumar
Welcome dear...