php PhpMailer SMTP 注意:检查是否连接时捕获到 EOF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35783718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PhpMailer SMTP NOTICE: EOF caught while checking if connected
提问by Max G
I got an issue with phpMailer, i can't send any e-mail, and it gives me this error:
我遇到了 phpMailer 的问题,我无法发送任何电子邮件,它给了我这个错误:
2016-03-03 21:32:09 SERVER -> CLIENT: 2016-03-03 21:32:09 SMTP NOTICE: EOF caught while checking if connected 2016-03-03 21:32:09 SMTP Error: Could not authenticate. 2016-03-03 21:32:09 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Erreur : SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
This is my code :
这是我的代码:
<?php require('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->SMTPAuth= true;
$mail->Username='[email protected]';
$mail->Password='passwordgmail';
$mail->Port = 587;
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl';
$mail->SetFrom('[email protected]', 'Name');
$mail->AddAddress('[email protected]', 'HisName');
$mail->Subject = 'Subject';
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()) {
echo 'Error : ' . $mail->ErrorInfo;
} else {
echo 'Ok!!';
}
?>
I tried all the answers i found, but none of them worked so far. I also tried other ports, the 25 and 465 don't work and give me other errors. If someone could help me please it would be really nice =) . Thank you
我尝试了我找到的所有答案,但到目前为止都没有奏效。我还尝试了其他端口,25 和 465 不工作并给我其他错误。如果有人可以帮助我,那就太好了 =) 。谢谢
回答by Synchro
You're using SMTPSecure = 'ssl'
with Port = 587
. That won't work. Use ssl
/ 465 or tls
/ 587; don't mix them up. This (and many other problems) are covered in the troubleshooting guide the error message links to.
您正在使用SMTPSecure = 'ssl'
与Port = 587
. 那行不通。使用ssl
/465 或tls
/587;不要把它们混在一起。这个(以及许多其他问题)在故障排除指南中包含错误消息链接。
Also note that the ssl:
prefix in your Host
value will override the value in SMTPSecure
, so I'd suggest you remove it from there.
另请注意,ssl:
您的Host
值中的前缀将覆盖 中的值SMTPSecure
,因此我建议您从那里删除它。
回答by Justin J
require('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->IsSMTP(true);
$mail->Host = 'smtp.gmail.com'; // not ssl://smtp.gmail.com
$mail->SMTPAuth= true;
$mail->Username='[email protected]';
$mail->Password='passwordgmail';
$mail->Port = 465; // not 587 for ssl
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl';
$mail->SetFrom('[email protected]', 'Name');
$mail->AddAddress('[email protected]', 'HisName');
$mail->Subject = 'Subject';
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send()) {
echo 'Error : ' . $mail->ErrorInfo;
} else {
echo 'Ok!!';
}
https://www.google.com/settings/u/0/security/lesssecureappsenable this
https://www.google.com/settings/u/0/security/lesssecureapps启用此功能