2017-02-28 85 views
1

我想使用的PHPMailer, 我已經啓用opensll和它加載 我使用XAMPP和PHPStorm不能理解PHPMailer的調試日誌

SERVER -> CLIENT: 220 smtp.gmail.com ESMTP z88sm9679wrb.26 - gsmtp 
CLIENT -> SERVER: EHLO PhpStorm 2016.1.2 
SERVER -> CLIENT: 501-5.5.4 HELO/EHLO argument "PhpStorm 2016.1.2" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo z88sm9679wrb.26 - gsmtp 
SMTP ERROR: EHLO command failed: 501-5.5.4 HELO/EHLO argument "PhpStorm 2016.1.2" invalid, closing connection.501 5.5.4 https://support.google.com/mail/?p=helo z88sm9679wrb.26 - gsmtp 
CLIENT -> SERVER: HELO PhpStorm 2016.1.2 
SERVER -> CLIENT: 
SMTP ERROR: HELO command failed: 
SMTP NOTICE: EOF caught while checking if connected 
SMTP Error: Could not connect to SMTP host. 
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 
Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 

這裏是我的代碼

<?php 
/** 
* This example shows settings to use when sending via Google's Gmail servers. 
*/ 

//SMTP needs accurate times, and the PHP time zone MUST be set 
//This should be done in your php.ini, but this is how to do it if you don't have access to that 
date_default_timezone_set('Etc/UTC'); 

require '../PHPMailerAutoload.php'; 

//Create a new PHPMailer instance 
$mail = new PHPMailer; 

//Tell PHPMailer to use SMTP 
$mail->isSMTP(); 

//Enable SMTP debugging 
// 0 = off (for production use) 
// 1 = client messages 
// 2 = client and server messages 
$mail->SMTPDebug = 2; 

//Ask for HTML-friendly debug output 
$mail->Debugoutput = 'html'; 

//Set the hostname of the mail server 
$mail->Host = 'smtp.gmail.com'; 
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 
$mail->Port = 587; //ssl : 465 --- tls:587; 
//Set the encryption system to use - ssl (deprecated) or tls 
$mail->SMTPSecure = 'tls'; 

//Whether to use SMTP authentication 
$mail->SMTPAuth = true; 

//Username to use for SMTP authentication - use full email address for gmail 
$mail->Username = "[email protected]"; 

//Password to use for SMTP authentication 
$mail->Password = "*****"; 

//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'Abou May'); 

//Set an alternative reply-to address 
//$mail->addReplyTo('[email protected]', 'First Last'); 

//Set who the message is to be sent to 
$mail->addAddress('[email protected]', 'Abou May'); 

//Set the subject line 
$mail->Subject = 'PHPMailer GMail SMTP test'; 

//Read an HTML message body from an external file, convert referenced images to embedded, 
//convert HTML into a basic plain-text alternative body 
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__)); 

//Replace the plain text body with one created manually 
$mail->AltBody = 'This is a plain-text message body'; 

//Attach an image file 
$mail->addAttachment('images/phpmailer_mini.png'); 

//send the message, check for errors 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 


I have read lots of documentation, bu I cannot figure out the reason of this error. 

可有人givz我的例子代碼?

出了什麼問題?

我讀了所有的故障排除

節「SMTP錯誤:無法連接到SMTP主機」

這也可能顯示爲SMTP連接()失敗或調用郵件(),而不連接在調試輸出。這通常被稱爲PHPMailer問題,但幾乎總是由本地DNS故障,防火牆阻塞(例如GoDaddy所做的)或本地網絡上的其他問題導致。這意味着PHPMailer無法聯繫您在Host屬性中指定的SMTP服務器,但並未明確說明原因。它也可能是由於沒有加載openssl擴展引起的(請參閱下面的加密註釋)。

+0

Smtp在您的Google帳戶中啓用? – DarkSideKillaz

+0

我不知道這是否是原因,但在我的情況下,我不得不登錄我的gmail帳戶並在那裏更改設置,例如「允許遠程應用程序的安全性較低的登錄信息..」。我不記得他們稱之爲什麼該設置 –

回答

0

我也遇到這樣的問題before.This不是PhpMailer.But的實際上的問題,這是導致由Gmail的SMTP被拒絕的連接,所以你無法連接。 爲了解決這個問題,你需要

Google Developer Console配置一個OAuth2應用。 步驟是here

如果仍然不能設法解決這個問題,我建議你使用Postmark作爲您的郵件服務器,它是一個更容易建立連接。

Here是Postmark.For的設置引導我來說是一個很大easier.Hope它幫助。

+0

情況並非如此。切換到OAuth可解決其他問題,但這不是其中之一。 – Synchro

0

這是無關的Gmail或OAuth的。

的問題是這一行:

CLIENT -> SERVER: EHLO PhpStorm 2016.1.2 

當PHPMailer的的SMTP客戶打招呼,以這樣的服務器,默認情況下它經過內部方法serverHostname()返回的名稱。通常這將返回類似localhost.localdomain,或mymac.local(即一臺真實主機名),但如果這是不可用的,它試圖找出使用什麼 - 它回落到的事情之一是$_SERVER['SERVER_NAME']超級全球,在這種case包含PhpStorm 2016.1.2(我猜是因爲您正在使用PHPStorm的內置Web服務器進行測試?),這不是有效的主機名,因此是錯誤。這對於PHPStorm來說並不是一個好的舉措,可能值得報告爲一個錯誤。

幸運的您可以覆蓋使用Helo屬性,像這樣的場合恰恰存在於客戶端主機的自動確定。只是這樣做:

$mail->Helo = 'my.host.name'; 

代要麼不管你的真實主機名,或通過調用一些其他的功能,這使得可用的結果。