当我点击回复按钮时,我希望能够回复使用 $email 而不是我用来发送表单的电子邮件 (someone@gmail.com) 发送电子邮件的用户。名称是正确的,只是不是电子邮件 http://oi50.tinypic.com/1z3auc0.jpg 现在我认为这些代码应该可以工作,但事实并非如此!我究竟做错了什么?
$mail->From = $email;
$mail->FromName = $name;
$mail->SetFrom($email, $name);
这是完整的邮件。
$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';
?>