【问题标题】:PHPMailer's infamous SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failedPHPMailer 臭名昭著的 SMTP 错误:无法连接到服务器:连接超时 (110) SMTP connect() 失败
【发布时间】:2014-02-11 04:50:23
【问题描述】:

我正在尝试让 PHPMailer 使用 Google Apps SMTP 服务器工作。我试过了:

  1. 在 php.ini 中取消注释 openssl
  2. 在端口 465 上远程登录 Google 的服务器(成功)
  3. 在端口 465 上远程登录我的网络服务器(成功)
  4. 从我的服务器远程登录 Google 的服务器(成功)
  5. 检查 DNS SPF/MX 记录(并清理到 IPv4)
  6. 端口 587 上的 tls
  7. webhost 确认他们允许出站 SMTP 流量
  8. 谷歌验证码的解锁技巧
  9. 阅读我在 StackOverflow 上可以找到的所有内容(解决方案涵盖上述内容)

有人可以提供连接超时的解决方案吗?

这是我的代码:

require_once ( 'class.phpmailer.php' ); // Add the path as appropriate
$Mail = new PHPMailer();
$Mail->IsSMTP(); // Use SMTP
$Mail->Host        = "smtp.gmail.com"; // Sets SMTP server
$Mail->SMTPDebug   = 1; // 2 to enable SMTP debug information
$Mail->SMTPAuth    = TRUE; // enable SMTP authentication
$Mail->SMTPSecure  = "ssl"; //Secure conection
$Mail->Port        = 465; // set the SMTP port
$Mail->Username    = 'account@googleappsaddress.com'; // SMTP account username
$Mail->Password    = 'mypassword'; // SMTP account password
$Mail->Priority    = 1; // Highest priority - Email priority (1 = High, 3 = Normal, 5 = low)
$Mail->CharSet     = 'UTF-8';
$Mail->Encoding    = '8bit';
$Mail->Subject     = 'Test Email Using Gmail';
$Mail->ContentType = 'text/html; charset=utf-8\r\n';
$Mail->From        = 'myemail@gmail.com';
$Mail->FromName    = 'GMail Test';
$Mail->WordWrap    = 900; // RFC 2822 Compliant for Max 998 characters per line

$Mail->AddAddress( $to ); // To:
$Mail->isHTML( TRUE );
$Mail->Body    = $body;
$Mail->AltBody = $MessageTEXT;
$Mail->Send();
$Mail->SmtpClose();

if(!$Mail->Send()) {
    $error = 'Mail error: '.$Mail->ErrorInfo; 
    echo($error);
    return false;
} else {
    $error = 'Message sent!';
    return true;
}

【问题讨论】:

  • 您是否与虚拟主机确认他们允许端口 465? “smtp”是端口 25。端口 465 是“ssmtp” - smtp over ssl,可能会因为它是不同的协议而被阻止
  • @MarcB,是的。我也成功通过 465 访问另一台服务器。
  • 检查服务器上没有运行应用级防火墙。如果命令行中的 telneting->google 可以工作,但网络服务器不能正常工作,则可能是某些东西阻止了网络服务器以这种方式读取。
  • 我可以从我的网络服务器(通过 ssh)telnet 到 gmail 的 SMTP 服务器的 465 端口

标签: php smtp phpmailer google-apps


【解决方案1】:

原来我是巧合的受害者。当我 ssh'ed 到我的服务器并远程登录到 Gmail 时,它是打开的 - 但是,由于 openssl 没有被取消注释,我怀疑这就是它最初失败的原因。

但是,在尝试使其正常工作时,主机防火墙将 Gmail 列入了黑名单。他们目前正在调查原因,但简短的回答是它已列入白名单并且可以正常工作。

【讨论】:

    猜你喜欢
    • 2014-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-29
    • 2015-09-25
    • 2016-07-14
    相关资源
    最近更新 更多