I have an html form on my website and have just done a php form to email to go with it using online tutorials etc.
But it will not work!!
When I test it, it always says there is no email entered even though there is!!
Can anyone help me please?
Very grateful for any input!!
here is the code:
Code: Select all
<?php
$to = "me@myemail.com" ;
$from = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$headers = "From: $from" ;
$subject = "Contact Form Data" ;
$fields = array();
$fields{"name"} = "Name" ;
$fields{"email"} = "Email" ;
$fields{"telephone"} = "Telephone" ;
$fields{"town"} = "Town" ;
$fields{"dogbreed"} = "Dog Breed" ;
$fields{"message"} = "Message" ;
$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
$headers2 = "From: admin@domain.co.uk";
$subject2 = "Thank you for contacting us";
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at http://www.domain.co.uk";
if($from == '') {print "You have not entered an email, please go back and try again";}
else {
if($name == '') {print "You have not entered a name, please go back and try again";}
else {
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.domain.com/thankyou.html" );}
else
{print "We encountered an error sending your mail, please notify webmaster@domain.com"; }
}
}
?>