简体   繁体   English

PHPMailer如何设置弹跳email地址

[英]PHPMailer how to set bounce email address

i know there are plenty of guides, but i tried so many of them with no result.我知道有很多指南,但我尝试了很多都没有结果。 I also tried to reshuffle the parameters so sender goes before replyTo and vice versa, etc, but still.我还尝试重新调整参数,以便发件人在回复之前进行,反之亦然,等等,但仍然如此。

The idea is to appear to the recpient as it came from something@gmail.com, but on reply (human or robot as bounce email) to always reply to noreply@custom.com这个想法是让收件人看到它来自something@gmail.com,但在回复(人类或机器人作为退回电子邮件)时始终回复 noreply@custom.com

No matter what I do, the bounced email always delives to something@gmail.com instead of noreply@custom.com无论我做什么,被退回的 email 总是发送到 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);

Any idea where is the problem?知道问题出在哪里吗? PHPMailer 6.1.6 PHPMailer 6.1.6

The bounce email address is the SMTP MAIL FROM address, also known as the envelope sender .退回的 email 地址是 SMTP MAIL FROM地址,也称为信封发件人 This is often the same as the From address (and PHPMailer uses the from address as the sender by default), but it is entirely normal for it to be different (subject to DMARC config).这通常与发件人地址相同(PHPMailer 默认使用发件人地址作为发件人),但它不同是完全正常的(取决于 DMARC 配置)。 In PHPMailer you set it by setting the Sender property, as you are doing in this line:在 PHPMailer 中,您可以通过设置Sender属性来设置它,就像您在这一行中所做的那样:

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

When a server receives a message, it takes the envelope sender and adds it to the message in a Return-Path header;当服务器接收到消息时,它获取信封发送者并将其添加到Return-Path header 中的消息中; this is not something that a sending server should ever do.这不是发送服务器应该做的事情。

So to change the bounce address, change that setting;因此,要更改退回地址,请更改该设置; it is mostly independent of from and reply-to addresses.它主要独立于发件人和回复地址。 Note however that gmail may ignore this if you have not configured it as an alias for your gmail username.但是请注意,如果您尚未将其配置为 gmail 用户名的别名,则 gmail 可能会忽略这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM