I'll admit it right up front that I'm a complete newbie and am having trouble. I have tried seraching for the answer to this and get the concept but can't make it work. I've just set up a form and understand that filtering out certain characters to prevent spamming and injection of headers is the wise thing to do. I've tried various bits of code but it's just not happening. If anyone could be so kind as to post back the full code including the below so I can see where it goes and what variables are used, I'd be very grateful. Any other tips on things to implement along these lines would be appreciated too (thinking of using a Captcha on the form page, but one step at a time...). Thanks
<?php
$to = $_REQUEST['SendTo'] ;
$from = $_REQUEST['Email'] ;
$namefirst = $_REQUEST['NameFirst'] ;
$namelast = $_REQUEST['NameLast'] ;
$headers = "From: $from";
$subject = "Enquiry";
$fields = array();
$fields{"NameFirst"} = "First Name";
$fields{"NameLast"} = "Last Name";
$fields{"Firm"} = "Firm";
$fields{"City"} = "City";
$fields{"Email"} = "Email Address";
$fields{"Phone"} = "Phone Number";
$fields{"Message"} = "Message";
$body = "The following information has been submitted via the website:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n\n",$b,$_REQUEST[$a]); }
$headers2 = "From: email@email.com";
$subject2 = "Thank you for your enquiry";
$autoreply = "We have received your enquiry. You will receive a phone call or email from me shortly.\n\nWith kind regards,\n\nOwner";
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.test.com/contact_submitted.htm" );}
else
{print "We encountered an error sending your mail, please notify webmaster@test.com"; }
?>
$to = $_REQUEST['SendTo'] ;
$from = $_REQUEST['Email'] ;
$namefirst = $_REQUEST['NameFirst'] ;
$namelast = $_REQUEST['NameLast'] ;
$headers = "From: $from";
$subject = "Enquiry";
$fields = array();
$fields{"NameFirst"} = "First Name";
$fields{"NameLast"} = "Last Name";
$fields{"Firm"} = "Firm";
$fields{"City"} = "City";
$fields{"Email"} = "Email Address";
$fields{"Phone"} = "Phone Number";
$fields{"Message"} = "Message";
$body = "The following information has been submitted via the website:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n\n",$b,$_REQUEST[$a]); }
$headers2 = "From: email@email.com";
$subject2 = "Thank you for your enquiry";
$autoreply = "We have received your enquiry. You will receive a phone call or email from me shortly.\n\nWith kind regards,\n\nOwner";
$send = mail($to, $subject, $body, $headers);
$send2 = mail($from, $subject2, $autoreply, $headers2);
if($send)
{header( "Location: http://www.test.com/contact_submitted.htm" );}
else
{print "We encountered an error sending your mail, please notify webmaster@test.com"; }
?>
