【发布时间】:2015-03-26 01:18:28
【问题描述】:
很抱歉添加到 PHPMailer / Gmail 问题的集合。我已经阅读了所有内容,但仍然无法使其正常工作。首先是错误信息:
2015-03-25 16:22:44 连接:打开
2015-03-25 16:22:54 SMTP 错误:无法连接到服务器:连接尝试失败 因为连接方在一段时间后没有正确响应 时间,或建立连接失败,因为连接的主机有 没有回应。 (10060) SMTP 连接()失败。消息不是 发送。邮件程序错误:SMTP connect() 失败。
此代码与我多次使用以从secureserver.net 帐户成功发送电子邮件的代码相同,因此我非常有信心该脚本是可靠的。问题一定出在我尝试使用的 gmail 设置中(?)。
try {
$mail = new PHPMailer(true);
$mail->IsSMTP(); // Using SMTP.
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 2; // Enables SMTP debug information - SHOULD NOT be active on production servers!
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = 'true'; // Enables SMTP authentication.
$mail->Host = "smtp.gmail.com"; // SMTP server host.
$mail->Port = 587; // Setting the SMTP port for the GMAIL server.
$mail->Username = "XXXXXXXXXX@gmail.com"; // SMTP account username (GMail email address).
$mail->Password = "XXXXXXXXXX"; // SMTP account password.
$mail->AddReplyTo('XXXXXXXXXX@gmail.com', 'me'); // Use this to avoid emails being classified as spam - SHOULD match the GMail email!
$mail->AddAddress('someone.else@gmail.com', 'Someone Else'); // Recipient email / name.
$mail->SetFrom('XXXXXXXXXX@gmail.com', 'me'); // Sender - SHOULD match the GMail email.
$mail->Subject = 'PHPMailer Test Subject via smtp, basic with authentication';
$mail->Body = 'Test Body';
$mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';
// $mail->MsgHTML($message);
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
我也尝试过端口 465/ssl(甚至是 25,尽管这几乎肯定行不通)。我用 telnet 验证我可以到达 587 端口:
telnet smtp.gmail.com 587
正在尝试 2607:f8b0:4001:c11::6c...
已连接 到 gmail-smtp-msa.l.google.com。
转义字符是'^]'。
220 mx.google.com ESMTP f1sm1137441igt.14 - gsmtp
我错过了什么?我已经经历了几个小时,我没有发现任何问题。谢谢!
【问题讨论】:
-
你能试试
$mail->SMTPAuth = true;(作为真正的布尔值)吗? -
我做到了。很多次。结果相同。