【问题标题】:PHPmailer custom header set, but not shown on deliveryPHPmailer 自定义标头集,但未在交付时显示
【发布时间】:2021-03-23 00:19:22
【问题描述】:

我使用的是 PHPMailer6.2.0,但在设置返回路径时遇到问题。

我已经通过 PHPmailer 函数 addCustomHeader() 添加了自定义标头

$mail->addCustomHeader("Return-Path", $fromemail);

为了调试,我在第 1794 行打印了 \PHPMailer\PHPMailer.php 函数 mailSend($header, $body) 中的标头内容;

var_export($header);
die();

这会在发送之前打印出标头内容,并验证自定义标头返回路径是否设置正确,但是实际上,当我收到一封发给我的 Outlook 的电子邮件时,标头返回路径会回调到域默认值电子邮件 user@domain.com。也许这不是电子邮件发送前的最后一个地方,然后它会丢失?

我使用 DirectAdmin 作为我的服务器管理器

【问题讨论】:

    标签: php phpmailer directadmin custom-headers


    【解决方案1】:

    你在mailSend函数中看到上面的评论了吗? 发送者被接收者变成了返回路径头!

    <?php
        $params = null;
        //This sets the SMTP envelope sender which gets turned into a return-path header by the receiver
        //A space after `-f` is optional, but there is a long history of its presence
        //causing problems, so we don't use one
        //Exim docs: http://www.exim.org/exim-html-current/doc/html/spec_html/ch-the_exim_command_line.html
        //Sendmail docs: http://www.sendmail.org/~ca/email/man/sendmail.html
        //Qmail docs: http://www.qmail.org/man/man8/qmail-inject.html
        //Example problem: https://www.drupal.org/node/1057954
        // CVE-2016-10033, CVE-2016-10045: Don't pass -f if characters will be escaped.
        if (!empty($this->Sender) && static::validateAddress($this->Sender) && self::isShellSafe($this->Sender)) {
            $params = sprintf('-f%s', $this->Sender);
        }
    

    我认为您不应该自己设置返回路径标头。我相信 PHPMailer 使用发件人自动处理这个问题。但如果我错了,请纠正我。

    【讨论】:

    • 是的,显然它确实如此,正如上面的评论所提到的。我没有注意到该功能注释,对此我很抱歉,可能会节省一些时间。但是,嘿?生活和学习,我猜。感谢您的意见!
    【解决方案2】:

    停在那里!发件人应该设置return-path 标头。该标头由接收者添加,其中的内容取决于 SMTP 信封发件人,即发送邮件的 SMTP MAIL FROM 命令中使用的地址。将此标头设置为发件人是对 RFC 的直接违反。那么你应该怎么做呢?设置信封发件人,然后在 PHPMailer 中这样做:

    $mail->Sender = $fromemail;
    

    即使你这样做了,你发送的服务器是否接受它是另一回事。例如,gmail 将不允许您使用除帐户用户名地址或预定义别名以外的任何内容,而不是任意地址。

    【讨论】:

    • 感谢 1000!我可能需要很长时间才能找到这个,返回路径现在是正确的!你是救命恩人!!!!
    猜你喜欢
    • 2020-06-20
    • 2016-01-25
    • 2010-12-21
    • 2021-09-04
    • 1970-01-01
    • 2012-05-13
    • 2020-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多