Jump to content

Need advise on getting the reply function working


Go to solution Solved by cyberRobot,

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

  • Solution

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.
Edited by cyberRobot
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.