我的问题:
使用PHPMailer使用localhost主机时,我无法发送经过validation的SMTP电子邮件。 我不明白为什么这样。
我意识到这个问题的核心根源几乎肯定是一个Exim的设置,而不是PHPMailer,但我找不到解决这个问题的工作解决scheme。
关于我的服务器:
我有我自己的服务器,其中设置了Exim 4.87和PHPMailer 5.2.16。 服务器上有大约100个帐号,其中很多用户拥有自己的邮件列表等等。
服务器运行帐户DNS,SMTP和托pipe所有在同一个地方,所以调用Exim邮件程序的PHP脚本不需要离开服务器,它都是本地的。
尝试修复:
与此问题类似的症状。 阅读这篇文章后,我放宽了Exim的设置,允许任何人(PHP)的电子邮件和Exim中的各种其他津贴:
是的,我已阅读关于未发送/失败电子邮件的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 = '...!...';
我可以validationTLS的正确端口是487,普通SMTP的正确端口是25.用户名和密码是正确的。 当主机不是Localhost主机时,上面的细节工作。 但本地主机不接受任何发送身份validation。
我的问题是,对于电子邮件validation目的(和良好做法),我需要validation外发的电子邮件,但我只能validation它们,如果主机是远程主机而不是本地主机。
这对我来说,导致我想删除2秒的延迟 。 我意识到延迟来自authentication以及来自SMTPSecure 。 这个答案给了我有关使用本地主机缓解这种延迟的指针,这对我来说是完全有意义的,但不知何故服务器设置不接受这一点。
我有一个标准的PHPMailer设置使用Host->localhost ,它工作正常,除了它不使用SMTP身份validation或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身份validation可以在本地主机上工作?
如果需要,我可以告诉你debugging日志从成功发送时, Host->"serverdomain.co.uk"; 或Host->"accountdomain.co.uk"; 。 干杯
编辑:
OpenSSL在PHP上启用。
编辑2
Exim conf文件authentication(部分)
#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