PhpMailer不发送邮件 - TLS错误? [英] PhpMailer not sending mails - TLS error?
问题描述
发送电子邮件的代码是:
$ mail_User =site@xxxxxxx.com;
$ mail_Password =我的密码;
$ mail_address =site@xxxxxxx.com;
$ mail_Name =MyName;
$ mail_Server =222.222.222.222;
$ mail_Port = 25;
函数SendHTMLMail($ to,$ cc,$ bcc,$ subject,$ body)
{
全局$ mail_User,$ mail_Password,$ mail_address,$ mail_Name,$ mail_Server ,$ mail_Port;
$ correo = new PHPMailer;
$ correo-> SMTPDebug = 3; //启用详细调试输出
$ correo-> SetLanguage(es,/ phpmailer / language /);
$ correo-> IsSMTP();
$ correo-> IsHTML(true);
$ correo-> Host = $ mail_Server;
$ correo-> Port = $ mail_Port;
$ correo-> SMTPAuth = true;
// $ correo-> SMTPSecure ='tls'; //启用TLS加密,`ssl`也接受
$ correo-> Username = $ mail_User;
$ correo-> Password = $ mail_Password;
$ correo-> From = $ mail_address;
$ correo-> FromName = $ mail_Name;
$ correo-> Subject = $ subject;
$ correo-> Body = $ body;
$ dest = explode(;,$ to); ($ n = 0; isset($ dest [$ n]); $ n ++)$ corre-> AddAddress($ dest [$ n]);
$ dest = explode(;,$ cc); ($ n = 0; isset($ dest [$ n]); $ n ++)$ corre-> AddCC($ dest [$ n]);
$ dest = explode(;,$ bcc); ($ n = 0; isset($ dest [$ n]); $ n ++)$ corre-> AddBCC($ dest [$ n]);
if($ correo-> Send())
return;
else {
AddLog(Correo no enviado:$ correo-> ErrorInfo);
echo< br> Correo no enviado:$ correo-> ErrorInfo< br>;
returnCorreo no enviado:$ correo-> ErrorInfo;
}
}
结果是:
2016-02-24 04:58:17连接:打开到222.222.222.222:25,timeout = 300,options = array(
)
2016-02-24 04:58:17连接:打开
2016-02-24 04:58:17服务器 - >客户:220-srv1.abcdef.com ESMTP Exim 4.86#2 Wed,24 Feb 2016 14:47:17 +0100
220 - 我们不授权使用此系统运输未经请求,
220和/或批量电子邮件。
2016-02-24 04:58:17客户 - >服务器:EHLO www.site.com
2016-02-24 04:58:18服务器 - >客户:250-srv1.abcdef.com您好www.doznyk.com [181.181.181.181]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-02-24 04:58:18客户 - > SERVER:STARTTLS
2016-02-24 04:58:18 SERVER - >客户端:220 TLS继续
2016-02-24 04:58:18 SMTP错误:无法连接到SMTP主机。
2016-02-24 04:58:18客户 - > SERVER:QUIT
2016-02-24 04:58:19 SERVER - >客户端:221 srv1.abcdef.com关闭连接
2016-02-24 04:58:19连接:关闭
2016-02-24 04:58:19 SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
为什么phpmailer不发送电子邮件?为什么尝试使用TLS,如果代码行是一个注释?
我用假的方式替换敏感数据,如服务器名称和IP。
如果我将端口从25更改为587并取消注释行tls,结果几乎相同。
谢谢
新测试,结果相同。
我以Synchro向我推荐文章。
我将端口从25更改为587,并将行$ correo-> SMTPAutoTLS = true;
$ correo - > SMTPAuth = true;
$ correo-> SMTPAutoTLS = true;
// $ correo-> SMTPSecure ='tls'; //启用TLS加密,`ssl`也接受
$ correo-> Username = $ mail_User;
$ correo-> Password = $ mail_Password;
结果是:
2016-02-24 06:05:36连接:打开到222.222.222.222:587,timeout = 300,options = array(
)
20162-24 06 :05:37连接:打开
2016-02-24 06:05:37 SERVER - >客户:220-srv1.abcdef.com ESMTP Exim 4.86#2 Wed,24 Feb 2016 15:54:37 +0100
220-我们不授权使用此系统运输未经请求的
220和/或批量电子邮件。
2016-02-24 06:05:37客户 - >服务器:EHLO www.myserver.com
2016-02-24 06:05:38 SERVER - >客户:250-srv1.abcdef.com您好www.doznyk.com [181.229.171.247]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-02-24 06:05:38客户 - > SERVER:STARTTLS
2016-02-24 06:05:38 SERVER - >客户端:220 TLS继续
2016-02-24 06:05:39 SMTP错误:无法连接到SMTP主机。
2016-02-24 06:05:39客户 - > SERVER:QUIT
2016-02-24 06:05:39 SERVER - >客户:221 srv1.abcdef.com关闭连接
2016-02-24 06:05:39连接:关闭
嗯。我进行了很多测试,看不到文档说Syngro的部分,但Synchro是对的。
我添加了下一个代码,现在工作正常! p>
$ correo-> SMTPOptions = array(
'ssl'=>数组(
'verify_peer' => false,
'verify_peer_name'=> false,
'allow_self_signed'=> true
)
);
虽然我不使用SSL,但我必须澄清一点,我不使用SSL,因为phpmailer验证SSL可用
或必须正确配置
谢谢!
I have a problem sending emails with phpmailer .
The code that sends emails is:
$mail_User = "site@xxxxxxx.com";
$mail_Password = "My Password";
$mail_address = "site@xxxxxxx.com";
$mail_Name = "MyName";
$mail_Server = "222.222.222.222";
$mail_Port = 25;
function SendHTMLMail($to, $cc, $bcc, $subject, $body)
{
global $mail_User, $mail_Password, $mail_address, $mail_Name, $mail_Server, $mail_Port;
$correo = new PHPMailer;
$correo->SMTPDebug = 3; // Enable verbose debug output
$correo->SetLanguage("es", "/phpmailer/language/");
$correo->IsSMTP();
$correo->IsHTML(true);
$correo->Host = $mail_Server;
$correo->Port = $mail_Port;
$correo->SMTPAuth =true;
//$correo->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$correo->Username = $mail_User;
$correo->Password = $mail_Password;
$correo->From = $mail_address;
$correo->FromName = $mail_Name;
$correo->Subject = $subject;
$correo->Body = $body;
$dest = explode (";", $to);
for ($n=0; isset($dest[$n]); $n++) $correo->AddAddress($dest[$n]);
$dest = explode (";", $cc);
for ($n=0; isset($dest[$n]); $n++) $correo->AddCC($dest[$n]);
$dest = explode (";", $bcc);
for ($n=0; isset($dest[$n]); $n++) $correo->AddBCC($dest[$n]);
if ($correo->Send())
return "";
else {
AddLog("Correo no enviado: $correo->ErrorInfo");
echo "<br>Correo no enviado: $correo->ErrorInfo<br>";
return "Correo no enviado: $correo->ErrorInfo";
}
}
And the result is :
2016-02-24 04:58:17 Connection: opening to 222.222.222.222:25, timeout=300, options=array (
)
2016-02-24 04:58:17 Connection: opened
2016-02-24 04:58:17 SERVER -> CLIENT: 220-srv1.abcdef.com ESMTP Exim 4.86 #2 Wed, 24 Feb 2016 14:47:17 +0100
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
2016-02-24 04:58:17 CLIENT -> SERVER: EHLO www.site.com
2016-02-24 04:58:18 SERVER -> CLIENT: 250-srv1.abcdef.com Hello www.doznyk.com [181.181.181.181]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-02-24 04:58:18 CLIENT -> SERVER: STARTTLS
2016-02-24 04:58:18 SERVER -> CLIENT: 220 TLS go ahead
2016-02-24 04:58:18 SMTP Error: Could not connect to SMTP host.
2016-02-24 04:58:18 CLIENT -> SERVER: QUIT
2016-02-24 04:58:19 SERVER -> CLIENT: 221 srv1.abcdef.com closing connection
2016-02-24 04:58:19 Connection: closed
2016-02-24 04:58:19 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Why phpmailer don't send emails? Why it try to use TLS if the code line is a comment?
I replace sensitive data with fake, like server name and IPs. If I change port from 25 to 587 and uncomment the line tls, the result is almost the same.
Thank you
New test, same result.
I read the doc as Synchro suggest me. I changed the port from 25 to 587 and added the line $correo->SMTPAutoTLS = true;
$correo->SMTPAuth =true;
$correo->SMTPAutoTLS = true;
//$correo->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$correo->Username = $mail_User;
$correo->Password = $mail_Password;
The result is:
2016-02-24 06:05:36 Connection: opening to 222.222.222.222:587, timeout=300, options=array (
)
2016-02-24 06:05:37 Connection: opened
2016-02-24 06:05:37 SERVER -> CLIENT: 220-srv1.abcdef.com ESMTP Exim 4.86 #2 Wed, 24 Feb 2016 15:54:37 +0100
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
2016-02-24 06:05:37 CLIENT -> SERVER: EHLO www.myserver.com
2016-02-24 06:05:38 SERVER -> CLIENT: 250-srv1.abcdef.com Hello www.doznyk.com [181.229.171.247]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-02-24 06:05:38 CLIENT -> SERVER: STARTTLS
2016-02-24 06:05:38 SERVER -> CLIENT: 220 TLS go ahead
2016-02-24 06:05:39 SMTP Error: Could not connect to SMTP host.
2016-02-24 06:05:39 CLIENT -> SERVER: QUIT
2016-02-24 06:05:39 SERVER -> CLIENT: 221 srv1.abcdef.com closing connection
2016-02-24 06:05:39 Connection: closed
Well. I made a lot of test and cannot see the section of doc that said me Synchro, but Synchro was right.
I added the next code and now works fine!
$correo->SMTPOptions = array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
);
Although I do not use SSL, I must clarify that I don't use SSL because phpmailer verifies that SSL is usable. Or must be configured properly
Thanks!
这篇关于PhpMailer不发送邮件 - TLS错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!