PHPMailer-Gmail设置-错误10060 [英] PHPMailer - Gmail settings - Error 10060

查看:37
本文介绍了PHPMailer-Gmail设置-错误10060的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很抱歉添加到PHPMailer/Gmail问题集合中。我都读过了,但还是不能让它起作用。首先显示错误消息:

2015-03-25 16:22:44连接:打开
2015-03-25 16:22:54 SMTP 错误:无法连接到服务器:连接尝试失败 因为连接方在一段时间后未正确响应 时间,或已建立的连接失败,因为连接的主机 没有回应。(10060)SMTP CONNECT()失败。消息不是 已发送。邮件程序错误: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 f1sm1137441 igt.14-gsmtp

我错过了什么?我已经考虑这件事好几个小时了,我看不出有什么问题。谢谢!

推荐答案

您选中the troubleshooting guide了吗?

使用SMTPDebug = 4调试低级别连接(相对于SMTP)问题。

您确定使用的是最新的PHPMailer吗?您的代码看起来像是来自旧示例。

最好将PHPMailer从测试中删除,因为我怀疑您的问题是级别较低。编写一个简单的脚本,只对端口587执行fsockopen并从中读取,如下所示:

<?php
$fp = fsockopen('tcp://smtp.gmail.com', 587, $errno, $errstr, 10);
echo fgets($fp, 128);
fclose($fp);

如果有效,您将从中看到类似220 mx.google.com ESMTP eo1sm5152802wib.16 - gsmtp的内容。

如果不起作用,可能会出现php.ini设置、禁用功能、缺少扩展等问题。

这篇关于PHPMailer-Gmail设置-错误10060的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆