roldahayes Posted March 8, 2013 Share Posted March 8, 2013 Hi, I need some advise on getting this contact form working correctly, It emails the message as it should but I need to have a reply header in there somewhere so the user can click reply in their email program to send an email back.. At the moment, it just replies to the website it came from. Hope this makes sense. <?php // get posted data into local variables $EmailTo = "me@mysite.co.uk";$Subject = "Contact Form:";$Name = Trim(stripslashes($_POST['Name'])); $Email = Trim(stripslashes($_POST['Email'])); $Phone = Trim(stripslashes($_POST['Phone'])); $Comments = Trim(stripslashes($_POST['Comments'])); //Assigning the REPLY FUNCTION$headers = "From: me@mysite.co.uk.co.uk\r\n";$headers .= "Reply-To: " . $email . "\n" ; // validation$validationOK=true;if (Trim($Name)=="") $validationOK=false;if (Trim($Email)=="") $validationOK=false;if (Trim($Comments)=="") $validationOK=false;if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-fields.php\">"; exit;} // prepare email body text$Body = "";$Body .= "Name: ";$Body .= $Name;$Body .= "\n";$Body .= "Email: ";$Body .= $Email;$Body .= "\n";$Body .= "Phone: ";$Body .= $Phone;$Body .= "\n";$Body .= "Comments: ";$Body .= $Comments;$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=contact-ok.php\">";}else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=contact-error.php\">";}?> Quote Link to comment https://forums.phpfreaks.com/topic/275402-need-advise-on-getting-the-reply-function-working/ Share on other sites More sharing options...
Solution cyberRobot Posted March 8, 2013 Solution Share Posted March 8, 2013 (edited) It looks like you're hard coding the headers argument for mail(): $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); What you're trying to do is shown in Example 2 here: http://php.net/manual/en/function.mail.php Side note: if you haven't done so already, you should review what's available for email injection attacks. https://www.google.com/search?q=php+mail+injection Edited March 8, 2013 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/275402-need-advise-on-getting-the-reply-function-working/#findComment-1417499 Share on other sites More sharing options...
roldahayes Posted March 8, 2013 Author Share Posted March 8, 2013 Thanks for the help, I changed it to: // send email $success = mail($EmailTo, $Subject, $Body, $headers); And it all works fine - thanks for the links about mail injections - I'll have a look Quote Link to comment https://forums.phpfreaks.com/topic/275402-need-advise-on-getting-the-reply-function-working/#findComment-1417531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.