首页 > 解决方案 > PHPmailer 自定义标头集,但未在交付时显示

问题描述

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

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

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

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

var_export($header);
die();

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

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

标签: phpphpmailerdirectadmincustom-headers

解决方案


您在 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 使用发件人自动处理这个。但如果我错了,请纠正我。


推荐阅读