2017-02-28 86 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'; 

代要么不管你的真实主机名,或通过调用一些其他的功能,这使得可用的结果。