为什么从 phpmailer 发送时,发件人会被 postfix 拒绝?

Why do I get a sender rejected from postfix when sending from phpmailer?

当我 运行 以下 PHP 代码时,我得到一个错误。

$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = SMTP::DEBUG_SERVER; // debug
$mail->Host = 'localhost';
$mail->Port = 25;
$mail->SMTPAuth = true;
$mail->Username = $uname;
$mail->Password = $pw;
$mail->CharSet = PHPMailer::CHARSET_UTF8;
$mail->setFrom('no-reply@example.com', 'website registration');
$mail->addAddress($cleaned_email);
$mail->Subject = 'Please verify your account';
$msg = '[registration text...]'
$msg = wordwrap($msg, 70);
$mail->Body = $msg;
                        
if (!$mail->send()) {
  echo $mail->ErrorInfo;
  exit();
} else {
  [... add user to db, etc...]
}

邮件似乎已发送。 PHPMailer 没有产生错误,数据库代码是 运行.

这是mail.log中产生的错误。

Aug 22 11:47:06 server postfix/smtp[8339]: 079AB1F909: to=<outsider-at-anydomain.com>, relay=mail.brighthouse.com[47.43.26.56]:25, delay=5.7, delays=0.06/0.02/0.31/5.3, dsn=2.0.0, status=sent (250 2.0.0 <user-at-example.com> sender rejected. Please see understanding-email-error-codes for more information.)

我已经尝试在 PHP 代码中更改发送地址给我的用户,我正在使用该地址进行身份验证。

我尝试将具有匹配散列 table 的 smtpd_sender_login_maps 参数添加到我的后缀配置中,以将无回复地址映射到我进行身份验证的用户,但它忽略了它作为未使用的参数。

后缀配置:

# See /usr/share/postfix/main.cf.dist for a commented, more complete version


# Debian specific:  Specifying a file name will cause the first
# line of that file to be used as the name.  The Debian default
# is /etc/mailname.
#myorigin = /etc/mailname

smtpd_banner = $myhostname ESMTP $mail_name (Raspbian)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

readme_directory = no

# See http://www.postfix.org/COMPATIBILITY_README.html -- default to 2 on
# fresh installs.
compatibility_level = 2

# TLS parameters
smtpd_tls_cert_file = /etc/letsencrypt/live/www.example.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/www.example.com/privkey.pem
#smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
#smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
smtpd_use_tls=yes
smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

# See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
# information on enabling SSL in the smtp client.

smtpd_relay_restrictions =
        permit_mynetworks
        permit_sasl_authenticated
        defer_unauth_destination
myhostname = server
mydomain = example.com
virtual_alias_domains = example2.com
virtual_alias_maps = hash:/etc/postfix/virtual
alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
myorigin = $mydomain
mydestination = $myhostname, $mydomain, server, localhost.localdomain, localhost
relayhost = mail.brighthouse.com
mynetworks = 127.0.0.0/8
mailbox_size_limit = 0
recipient_delimiter = +
inet_interfaces = all
inet_protocols = ipv4
notify_classes = resource, software, 2bounce
home_mailbox = Maildir/
#mailbox_command =
mailbox_transport = lmtp:unix:private/dovecot-lmtp
smtpd_sender_restrictions = permit_sasl_authenticated
smtpd_recipient_restrictions =
        permit_sasl_authenticated,
        permit_mynetworks,
        reject_unauth_destination
        reject_sender_login_mismatch
smtpd_helo_required = yes
smtpd_helo_restrictions =
        permit_mynetworks,
        permit_sasl_authenticated,
        reject_invalid_helo_hostname,
        reject_non_fqdn_helo_hostname,
        reject_unknown_helo_hostname,
        check_helo_access hash:/etc/postfix/helo_access
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_sasl_auth_enable = yes
smtpd_sasl_security_options = noanonymous
smtpd_sasl_tls_security_options = noanonymous
smptd_sender_login_maps = hash:/etc/postfix/controlled_envelope_senders

“发件人”地址的语法不正确:

$mail->setFrom('no-reply at example dot com', 'website registration');

您需要使用有效的电子邮件地址,例如:

$mail->setFrom('no-reply@example.com', 'website registration');

我的问题与 PHP Mailer 无关。我发布的 php 代码有效。我的问题是我的电子邮件服务器设置。我在这里发布了一个关于超级用户的服务器相关问题:https://superuser.com/questions/1580944/soho-postfix-dovecot-configuration-for-small-web-app-and-user-base

谢谢大家的回复。