我的sSMTP设置存在问题。它正好用于发送电子邮件,我收到它们,但它完全忽略了我的“From:”标题! 如果sSMPT是通过php邮件功能触发的,则from地址始终为“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
答案 0 :(得分:0)
尝试将以下内容添加到您的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);
答案 1 :(得分:0)
我无法解决此问题。如果其他人遇到这个问题,你唯一可以尝试的是FromLineOverride=YES
,如果这不起作用,那你就差点搞砸了。
我是一个人,已经从sSMTP转变为常规的sendmail,这就像魅力一样。
干杯
答案 2 :(得分:0)
sSMTP是一种流行的选择,可以作为docker容器中php邮件中继的简单sendmail替代品。如果有人遇到这个问题,因为他们正在使用带有Docker容器的sMTP,并且无法在php电子邮件中显示正确的标题,那么我建议转到msmtp。它易于在标准的php docker镜像中安装和使用。