我有一个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
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
<?php require('phpmailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = 'ssl://smtp.gmail.com';
$mail->SMTPAuth= true;
$mail->Username='myadress@gmail.com';
$mail->Password='passwordgmail';
$mail->Port = 587;
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl';
$mail->SetFrom('myadress@gmail.com', 'Name');
$mail->AddAddress('someone@gmail.com', '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!!';
}
?>
Run Code Online (Sandbox Code Playgroud)
我尝试了所有找到的答案,但到目前为止都没有.我也试过其他端口,25和465不工作,并给我其他错误.如果有人可以帮助我,那将是非常好的=).谢谢
Syn*_*hro 24
您正在使用SMTPSecure = 'ssl'与Port = 587.那不行.使用ssl/ 465或tls/ 587; 不要混淆它们.错误消息链接到的故障排除指南中介绍了此(以及许多其他问题).
另请注意,值中的ssl:前缀Host将覆盖其中的值SMTPSecure,因此我建议您将其从中删除.
小智 5
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='myadress@gmail.com';
$mail->Password='passwordgmail';
$mail->Port = 465; // not 587 for ssl
$mail->SMTPDebug = 2;
$mail->SMTPSecure = 'ssl';
$mail->SetFrom('myadress@gmail.com', 'Name');
$mail->AddAddress('someone@gmail.com', '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!!';
}
Run Code Online (Sandbox Code Playgroud)
https://www.google.com/settings/u/0/security/lesssecureapps启用此功能