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 = "[email protected]";$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: [email protected]\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\">";}?> Link to comment https://forums.phpfreaks.com/topic/275402-need-advise-on-getting-the-reply-function-working/ Share on other sites More sharing options...
cyberRobot Posted March 8, 2013 Share Posted March 8, 2013 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 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 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
Archived
This topic is now archived and is closed to further replies.