Jump to content

Need advise on getting the reply function working


roldahayes

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.