PHPMailer无法添加回复地址

7

我正在尝试给我的PHP邮件程序添加回复地址,但它只会将发件人设置为“我”,并回复到我的地址。

有什么想法我做错了什么吗?我已经添加了 $mail->AddReplyTo。我希望它能够回复发送网页表单的人。

$name = $_POST['name'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
$message = $_POST['message'];

$body             = file_get_contents('phpmailer/contents.html');
$body             = eregi_replace("[\]",'',$body);
$body             = eregi_replace("<name>", $name,$body);
$body             = eregi_replace("<telephone>", $telephone, $body);
$body             = eregi_replace("<email>", $email, $body);
$body             = eregi_replace("<message>", $message, $body);




$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "smtp.gmail.com"; // SMTP server
                    // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
$mail->Port       = 465;                   // set the SMTP port for the GMAIL server
$mail->Username   = "xxx@xxx.net";  // GMAIL username
$mail->Password   = "xxxxx"; 

$mail->AddReplyTo($email, $name);


$address = "xxxx.net";

$mail->AddAddress($address, "Contact form");

$mail->Subject    = " Contact Form";
1个回答

2
尝试的事情是要确保您正确传递了$email$name变量(添加一些调试语句来回显它们)。不确定您是否已经这样做,或者是否正在检查表单是否已发布。但那将是第一步。
通过我的PHPMailer和GMail使用,它们效果不佳。相反,我建议尝试phpGMailer脚本。 它对GMail非常有效。看看是否可以解决您的问题。
更新
思考一下,我认为GMail不允许更改ReplyTo地址,除非GMail帐户已激活该帐户的授权。我不确定这一点,但我知道通过Web界面是不可能的。
离题
我建议避免使用eregi_replace,因为它已过时。我会使用preg_replace代替。这是一个更新后的版本,以便您可以更新您的代码:
$body             = file_get_contents('phpmailer/contents.html');
$body             = preg_replace("~[\]~",'',$body);
$body             = preg_replace("~<name>~i", $name,$body);
$body             = preg_replace("~<telephone>~i", $telephone, $body);
$body             = preg_replace("~<email>~i", $email, $body);
$body             = preg_replace("~<message>~i", $message, $body);

谢谢Brad,这节省了我很多时间。我认为你关于Gmail回复的观点是正确的。我想他只能接受它。 - Roscoeh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接