sSMTP 发件人:标头不起作用


sSMTP From: header not working

我的sSMTP设置有问题。它正在发送电子邮件,我正在接收它们,但它完全忽略了我的"发件人:"标题!如果通过 php 邮件函数触发 sSMPT,则发件人地址始终为"http@mydomain.com",如果通过以 root 身份登录的 ssh 会话触发,则发件人地址始终为"root@mydomain.com"。所以我认为它总是使用当前用户并将其用作"发件人:"地址。

现在我知道您可以设置FromLineOverride=YES以允许使用您自己的发件人地址,我已经在我的 sSMPT 配置中设置了它,但这不起作用。只是完全忽略了这一点。

这是我的设置:

sSMTP 配置:

 # The user that gets all the mails (UID < 1000, usually the admin)
root=info@mydomain.com
# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable
mailhub=mydomain.com:587
# The address where the mail appears to come from for user authentication.
# rewriteDomain=info@mydomain.com
# i have tried this function above in different ways, doesnt change anything...
# The full hostname
hostname=mydomain.com
# Use SSL/TLS before starting negotiation
UseTLS=Yes
UseSTARTTLS=Yes
# Username/Password
AuthUser=info
AuthPass=password
# Email 'From header's can override the default domain?
FromLineOverride=YES

用于测试邮件功能的 php 脚本:

<?PHP
    $empfaenger = "user@gmail.com";
    $betreff = "Testing Mailserver";
    $text = "It seems to work";
    $extra = "From:Info <info@mydomain.com>'r'n";
// i have tried "From: Info..." with a space inbetween From: and Info.
    if(mail($empfaenger, $betreff, $text, $extra)) {
        echo 'E-Mail sent';
    }
?>
所以我没有收到任何错误,邮件通过,邮件服务器

在我的本地机器上运行并看到邮件,我可以确认邮件服务器没有更改发送地址,他只是从 sSMTP 获取他得到的东西。

我做错了什么?

干杯

编辑:按照DannySMc的建议尝试了以下操作

<?PHP
    $empfaenger = "user@gmail.com";
    $betreff = "Testing Mailserver";
    $text = "Seems to work";
    $extra = "From: no-reply@example.com 'r'n".
    'Reply-To: no-reply@example.com '."'r'n" .
    "Return-Path: no-reply@example.com'r'n" .
    'X-Mailer: PHP/' . phpversion();
    if(mail($empfaenger, $betreff, $text, $extra)) {
        echo 'E-Mail versendet';
    }
?>

仍然不起作用。我仍然看到来自 http@mydomain.com 的邮件

我无法解决此问题。如果其他人遇到此问题,您唯一可以尝试的就是FromLineOverride=YES如果这不起作用,那么您几乎就搞砸了。

就我而言,我已经从sSMTP转变为常规的sendmail,这就像一个魅力。

干杯

尝试以下方法将其添加到您的 php 脚本中:

$email_message = "Something here";
$email_subject = "a subject";
$email_recipient = "test@example.com";
$email_headers = "From: no-reply@example.com 'r'n".
    'Reply-To: no-reply@example.com '."'r'n" .
    "Return-Path: no-reply@example.com'r'n" .
    'X-Mailer: PHP/' . phpversion();
mail($email_recipient, $email_subject, $email_message, $email_headers);

sSMTP是一个流行的选择,作为docker容器中php邮件中继的简单sendmail替代品。如果有人遇到这个问题,因为他们将 sMTP 与 Docker 容器一起使用,并且无法让 from 标头在 php 电子邮件中正确显示,那么我建议迁移到 msmtp。它很容易在标准的 php docker 镜像中安装和使用。