【问题标题】:phpmailer can't add a reply to addressphpmailer 无法添加对地址的回复
【发布时间】:2011-04-28 16:09:37
【问题描述】:

我正在尝试向我的 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";

【问题讨论】:

    标签: php phpmailer


    【解决方案1】:

    可以尝试确保您的$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);
    

    【讨论】:

    • 感谢布拉德,这为我节省了很多时间,认为您对 gmail 回复的看法是正确的。认为他将不得不忍受它。
    猜你喜欢
    • 2012-11-25
    • 2013-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    相关资源
    最近更新 更多