我的问题:
使用 PHPMailer 时,我无法在使用localhost
主机时发送经过身份验证的 SMTP 电子邮件。我不明白为什么会这样。
我意识到这里问题的核心根源几乎肯定是 Exim 上的设置,而不是 PHPMailer,但我找不到任何可行的解决方案来解决这个问题。
关于我的服务器:
我有自己的服务器,其中安装了 Exim 4.87 和 PHPMailer 5.2.16。该服务器上有大约 100 个帐户,其中许多都有自己的邮件列表等。
服务器在同一个地方运行帐户 DNS、SMTP 和托管,因此调用 Exim 邮件程序的 PHP 脚本不需要离开服务器,它们都是本地的。
尝试修复:
类似症状这个问题读完这篇文章后,我放宽了 Exim 设置,允许任何人(PHP)发送电子邮件,并允许 Exim 中的其他各种权限:
- 允许无人发送电子邮件 = 开启
- 信任 X-PHP-Script 标头来确定以 nobody = ON 身份运行的进程发送的电子邮件的发件人
- 需要远程(主机名/IP 地址)HELO = OFF
- 要求传入的 SMTP 连接发送与此服务器的本地域不匹配的 HELO。= 关闭
是的,我已经阅读PHPMailer 文档关于未发送/失败的电子邮件。
我的 PHPMailer 设置(仅重要相关部分):
//$this->Host = "server-hostname.co.uk"; //THis WORKS
//$this->Host = "account-domain.co.uk"; // this WORKS
$this->Host = "localhost"; // this FAILS
$this->SMTPAuth = true; // Only works on non-localhost Host.
//$this->Port = 25; //default.
$this->Username = '[email protected]';
$this->Password = '...!...';
我可以验证 TLS 的正确端口是 487,纯 SMTP 的正确端口是 25。用户名和密码正确。当主机不是 时,上述详细信息有效Localhost
。但 localhost 不接受任何发送身份验证。
我的问题是,出于电子邮件验证目的(和良好的实践),我需要验证发送的电子邮件,但只有当主机是远程主机而不是本地主机时,我才能验证它们。
对我来说这导致延迟 2 秒我想删除它。我意识到延迟既来自身份验证,也来自SMTPSecure
。这个答案给我关于使用本地主机来减轻这种延迟的指示,这对我来说完全有意义,但不知何故服务器设置不接受这一点。
我有一个标准的 PHPMailer 设置Host->localhost
,它运行良好,只是它不使用 SMTP 身份验证或 SMTPSecurity。
错误:
(SMTPDebug = 4)
注意:抱歉,域名不一致(.com 和 .co.uk),但您明白了......
2016-11-24 14:40:52 Connection: opening to localhost:25, timeout=20, options=array (
)
2016-11-24 14:40:52 Connection: opened
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "220-serverdomain.com ESMTP Exim 4.87 #1 Thu, 24 Nov 2016 14:40:52 +0000
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "220-serverdomain.com ESMTP Exim 4.87 #1 Thu, 24 Nov 2016 14:40:52 +0000
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "220- We do not authorize the use of this system to transport unsolicited,
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "220-serverdomain.com ESMTP Exim 4.87 #1 Thu, 24 Nov 2016 14:40:52 +0000
220- We do not authorize the use of this system to transport unsolicited,
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "220 and/or bulk e-mail.
"
2016-11-24 14:40:52 SERVER -> CLIENT: 220-serverdomain.com ESMTP Exim 4.87 #1 Thu, 24 Nov 2016 14:40:52 +0000
220- We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
2016-11-24 14:40:52 CLIENT -> SERVER: EHLO www.accountdomain.co.uk
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "250-SIZE 52428800
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
250-SIZE 52428800
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "250-8BITMIME
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
250-SIZE 52428800
250-8BITMIME
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "250-PIPELINING
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "250-AUTH PLAIN LOGIN
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "250-STARTTLS
"
2016-11-24 14:40:52 SMTP -> get_lines(): $data is "250-serverdomain.com Hello www.accountdomain.co.uk [::1]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
"
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "250 HELP
"
2016-11-24 14:40:52 SERVER -> CLIENT: 250-serverdomain.com Hello www.accountdomain.co.uk [::1]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-11-24 14:40:52 CLIENT -> SERVER: STARTTLS
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "220 TLS go ahead
"
2016-11-24 14:40:52 SERVER -> CLIENT: 220 TLS go ahead
2016-11-24 14:40:52 SMTP Error: Could not connect to SMTP host.
2016-11-24 14:40:52 CLIENT -> SERVER: QUIT
2016-11-24 14:40:52 SMTP -> get_lines(): $data is ""
2016-11-24 14:40:52 SMTP -> get_lines(): $str is "221 serverdomain.com closing connection
"
2016-11-24 14:40:52 SERVER -> CLIENT: 221 serverdomain.com closing connection
2016-11-24 14:40:52 Connection: closed
2016-11-24 14:40:52 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我应该在 Exim(或其他地方)上进行哪些更改,以便 SMTP 身份验证可以正常工作本地主机?
如果需要,我可以向您显示成功发送时的调试日志Host->"serverdomain.co.uk";
。Host->"accountdomain.co.uk";
谢谢
编辑:
PHP 上启用了 OpenSSL。
编辑2
Exim conf 文件身份验证(部分)
#BEGIN ACL_NOTQUIT_BLOCK
# BEGIN INSERT ratelimit
# ignore authenticated hosts
accept authenticated = *
accept hosts = : +recent_authed_mail_ips : +loopback
warn
#only rate limit port 25
condition = ${if eq {$received_port}{25}{yes}{no}}
condition = ${if match {$smtp_notquit_reason}{command}{yes}{no}}
log_message = "Connection Ratelimit - $sender_fullhost because of notquit: $smtp_notquit_reason ($sender_rate/$sender_rate_period max:$sender_rate_limit)"
ratelimit = 1.2 / 1h / strict / per_conn
# END INSERT ratelimit
#END ACL_NOTQUIT_BLOCK