繁体   English   中英

PHPMailer的臭名昭著的SMTP错误:无法连接到服务器:连接超时(110)SMTP connect()失败

[英]PHPMailer's infamous SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed

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

  1. 在php.ini中取消注释openssl
  2. 在端口465上远程登录Google服务器(成功)
  3. 在端口465上远程登录我的Web服务器(成功)
  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;
}

原来我是巧合的受害者。 当我将服务器SSH并远程登录到Gmail时,它是打开的-但是,由于未对openssl进行注释,因此我怀疑这是它最初失败的原因。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM