【问题标题】:PHPMailer how to set bounce email addressPHPMailer如何设置退回邮件地址
【发布时间】:2020-11-27 01:09:49
【问题描述】:

我知道有很多指南,但我尝试了很多都没有结果。 我还尝试重新调整参数,以便发件人在 replyTo 之前进行,反之亦然,等等,但仍然如此。

这个想法是让收件人看到它来自 something@gmail.com,但在回复时(人工或机器人作为退回电子邮件)始终回复 noreply@custom.com

无论我做什么,退回的电子邮件总是发送到 something@gmail.com 而不是 noreply@custom.com

use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

require 'apps/PHPMailer/src/Exception.php';
require 'apps/PHPMailer/src/PHPMailer.php';
require 'apps/PHPMailer/src/SMTP.php';

try {
    $mail = new PHPMailer(true);

    $mail->CharSet = 'UTF-8';                                   // UTF8 Encoding
    $mail->Encoding = 'base64';                                 // Needs to be set with UTF8
    //$mail->SMTPDebug = SMTP::DEBUG_SERVER;                        // Enable verbose debug output
    $mail->isSMTP();                                            // Send using SMTP
    $mail->Host       = "smtp.gmail.com";                 // Set the SMTP server to send through
    $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
    $mail->Username   = "something@gmail.com";                     // SMTP username
    $mail->Password   = "somePassword";                // SMTP password
    $mail->SMTPSecure = "tls";
    $mail->Port       = 587;                 // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Sender
    $mail->setFrom('something@gmail.com');
    $mail->addReplyTo('noreply@custom.com');
    $mail->Sender = 'noreply@custom.com';

    // Recipient
    $mail->addAddress('fndsgfds@fsscd.com');

    // Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = "test bouncing";
    $mail->Body    = "teting";
    //$mail->AltBody = strip_tags($row_campaign['text']);
                                            
    $mail->MessageID = $messageId; // removed from example here, but is stated above
    $mail->addCustomHeader('In-Reply-To', $messageId);

    $mail->send();
}
catch (Exception $e) {
    echo "Error: {$mail->ErrorInfo}";
    die();
}
unset($mail);

知道问题出在哪里吗? PHPMailer 6.1.6

【问题讨论】:

  • 从地址试试这个:<something> noreply@custom.com
  • 您好,请详细说明,因为我不明白您的意思
  • 好吧,点击docs,我的观点变成了:$From = 'noreplay@custom.com'; $FromName='something';
  • 也不起作用...同样的问题
  • 我建议为此设置一个DMARC 记录。另外,请阅读this post

标签: php smtp phpmailer email-bounces


【解决方案1】:

退回电子邮件地址是 SMTP MAIL FROM 地址,也称为信封发件人。这通常与 From 地址相同(PHPMailer 默认使用 from 地址作为发件人),但它不同是完全正常的(取决于 DMARC 配置)。在 PHPMailer 中,您可以通过设置 Sender 属性来设置它,就像您在这一行中所做的那样:

$mail->Sender = 'noreply@custom.com';

当服务器接收一条消息时,它会获取信封发送者并将其添加到消息中的Return-Path 标头中;这不是发送服务器应该永远做的事情。

所以要更改退回地址,请更改该设置;它主要独立于发件人和回复地址。但是请注意,如果您没有将其配置为您的 gmail 用户名的别名,gmail 可能会忽略此。

【讨论】:

    猜你喜欢
    • 2014-04-07
    • 2020-12-19
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    相关资源
    最近更新 更多