簡體   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