0

when I hit the reply button I want to be able to reply to the user that sent the email using the $email NOT the email I used to send the form (someone@gmail.com). the name is correct just not the email http://oi50.tinypic.com/1z3auc0.jpg now i thought that these bits of code should work but they are not! what am I doing wrong?

   $mail->From     = $email;
   $mail->FromName = $name;
   $mail->SetFrom($email, $name);

here is the mailer in full.

    $mail = new PHPMailer;
    $mail->IsSMTP();                     // Set mailer to use SMTP
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only
    $mail->SMTPAuth = true;             // Enable SMTP authentication
    $mail->SMTPSecure = 'ssl';          // Enable encryption, 'ssl' also accepted
    $mail->Host = 'smtp.gmail.com';     // Specify main and backup server
    $mail->Port = 465;        // specify port
    $mail->Username = 'someone@gmail.com';      // SMTP username
    $mail->Password = 'password';                    // SMTP password
    $mail->WordWrap = 50;                                 // Set word wrap to 50   
    $mail->IsHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Quick Comment';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';



   // gets info from form
   $name = $_POST['name'] ;
   $email = $_POST['email'] ;
   $phone = $_POST['phone'] ;
   $message = $_POST['message'] ;



    // defines how message looks in email
   $mail->Body="
   Name: $name<br>
   Telephone: $phone<br>
   Email: $email<br>
   -------------------<br>
   Message:<br>
   $message";



    // makes email reply to user
   $mail->From     = $email;
   $mail->FromName = $name;
   $mail->SetFrom($email, $name);
   $mail->AddAddress('someone@gmail.com');  // send to


if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}

echo 'Message has been sent';

?>
user1785934
  • 13
  • 2
  • 5

3 Answers3

0

I think this post will be usefull for you: phpmailer: Reply using only "Reply To" address I think the AddReplyTo() function is the function you need.

Community
  • 1
  • 1
0

Something like $mail->AddReplyTo('example@example.com', 'Reply to name');

Danny
  • 1,185
  • 2
  • 12
  • 33
0

Most mail servers will not allow you to lie in the "From" header. This is a good thing, because spam filters react to lying. They either force your mail address into the "From" header no matter what you do, or will reject sending it out, or other crazy stuff.

The "Reply-to" header seems to be correctly set in your screen shot. And it is the only header that is valid for making the reply to an email go to a different address than the one it was originally sent from.

Sven
  • 69,403
  • 10
  • 107
  • 109