PHPMailer如何设置反弹电子邮件地址



我知道有很多指南,但我试了很多都没有结果。我还试图重新调整参数,使sender先于replyTo,反之亦然,等等,但仍然如此。

这个想法是为了让接受者看到它的由来something@gmail.com,但在回复时(人类或机器人作为反弹电子邮件(始终回复noreply@custom.com

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

use PHPMailerPHPMailerException;
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerSMTP;
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

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

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

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

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

最新更新