phpmailer无法添加回复地址

时间:2010-10-21 14:49:08

标签: php phpmailer

我正在尝试向我的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 个答案:

答案 0 :(得分:2)

要尝试的是确保正确传递$email$name变量(添加一些调试语句以回显它们)。不确定您是否已经这样做,或者您是否正在检查表单是否已发布。但这将是第一步。

从我使用PHPMailer和GMail开始,它们的效果不佳。相反,我建议尝试phpGMailer脚本。它适用于GMail。看看这是否无法解决您的问题。

<强>更新

考虑到这一点,我认为GMail不允许更改ReplyTo地址,除非GMail帐户已激活该帐户的授权。我对此并不是100%肯定,但我通过网络界面知道这是不可能的。

关闭主题

我会避免使用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);
相关问题