PHPMailer - Gmail settings - Error 10060(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:PHPMailer-Gmail设置-错误10060
				
        
 
            
        - 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
 - Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
 - PHP - if 语句中的倒序 2021-01-01
 - 覆盖 Magento 社区模块控制器的问题 2022-01-01
 - Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
 - PHP foreach() 与数组中的数组? 2022-01-01
 - 如何在 Symfony2 中正确使用 webSockets 2021-01-01
 - openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
 - 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
 - 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
 
