我看着下面的鏈接:的PHPMailer使用SMTP與Gmail不工作 - 連接超時
phpmailer send gmail smtp timeout
send email using Gmail SMTP server through PHP Mailer
http://uly.me/phpmailer-and-gmail-smtp/
...並試圖實施我自己是那些的組合...大多數時間它發送此消息...
Message could not be sent.
Mailer Error: SMTP connect() failed.
但是有一次在那裏發回當我「TLS」和「SSL」之間嘗試...
SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. Message could not be sent.
Mailer Error: SMTP connect() failed.
我的代碼附...爲什麼我莫名其妙地錯過了什麼?我問網絡託管服務是否阻止,並給他們一個我的代碼模板 - 他們說服務器允許連接到Gmail的SMTP。
require_once("class.phpmailer.php");
$mail = new PHPMailer();
$mail -> IsSMTP();
$mail -> SMTPDebug = 2;
$mail -> SMTPAuth = 'true';
$mail -> SMTPSecure = 'tls';
$mail -> SMTPKeepAlive = true;
$mail -> Host = 'smtp.gmail.com';
$mail -> Port = 587;
$mail -> IsHTML(true);
$mail -> Username = "[email protected]";
$mail -> Password = "mypassword";
$mail -> SingleTo = true;
$to = xxx;
$from = xxx;
$fromname = xxx;
$subject = xxx;
$message = xxx
$headers = "From: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$mail -> From = $from;
$mail -> FromName = $fromname;
$mail -> AddAddress($to);
$mail -> Subject = $subject;
$mail -> Body = $message;
if(!$mail -> Send()){
echo "Message could not be sent. <p>";
echo "Mailer Error: " . $mail-> ErrorInfo;
exit;
}
順便說一下,它對我自己的本地主機非常好,如果我發送我從那裏使用郵件 - 當我上傳到主機,但它錯誤。 – redber2009
我也研究過[鏈接](http://stackoverflow.com/questions/2867017/phpmailer-with-gmail-smtp-error)它沒有幫助,因爲我試驗了ssl和tls,它給出了相同的輸出 – redber2009
我編輯了我的答案,看看你是否錯過了它 – Krimson