2015-01-08 40 views
-1

所以我试图让PHPMailer工作,我已经下载了最新版本,并根据文档配置了它,我试过telnet smtp.gmail.com 587来检查我可以得到槽和那工程,我已经尝试ping smtp.gmail.com和那个作品,我已禁用谷歌的两步认证,我已经通过验证码验证。我还在我的Google安全设置中启用了应用程序访问权限。我曾尝试使用SSL与TLS,但无论我尝试,我仍然得到无法让PHPMailer工作

SMTP connect() failed. bool(false) 

这是我设置的时刻

<?php 

require("PHPMailer/PHPMailerAutoload.php"); // path to the PHPMailer class 

$mail = new PHPmailer; 

$mail->isSMTP(); 
$mail->SMTPAuth = true; 
$mail->SMTPDebug = 4; 
$mail->Mailer = 'smtp'; 
$mail->SMTPSecure = 'tls'; 
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 587; 
$mail->Username = '[email protected]'; 
$mail->Password = 'mypassword'; 


$mail->From = 'sndrem[email protected]'; 
$mail->FromName = 'Sindre Moldeklev'; 
$mail->addReplyTo('[email protected]', 'Reply adress'); 
$mail->addAddress('[email protected]', 'Full Name'); 

$mail->Subject = 'Here is an email'; 
$mail->Body = 'This is the body of the email'; 
$mail->AltBody = 'This is the alternative body'; 

echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n"; 

var_dump($mail->send()); 

?> 

我甚至增加了

echo (extension_loaded('openssl')?'SSL loaded':'SSL not loaded')."\n"; 

要检查openssl是否已加载,并返回已加载的SSL,以便确定。

这让我疯狂得不到这个工作。我试图通过xaamp在iMac 27“osx Yosemite v.10.10.1上运行它。我也从php.ini中取消了extension = openssl_dll的扩展名。

我觉得我已经试过了一切,但也许有人在这里有,我还没有尝试过一些额外的提示吗?

我任何答案,可以使我更接近的解决方案表示感谢。

有关的信息,这是剧本和服务器之间的最新消息。

SSL loaded 2015-01-08 17:25:59 Connection: opening to smtp.gmail.com:587, t=300, opt=array () 2015-01-08 17:25:59 Connection: opened 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "" 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "220 mx.google.com ESMTP ql3sm1265527lbb.48 - gsmtp " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "220 mx.google.com ESMTP ql3sm1265527lbb.48 - gsmtp " 2015-01-08 17:25:59 SERVER -> CLIENT: 220 mx.google.com ESMTP ql3sm1265527lbb.48 - gsmtp 2015-01-08 17:25:59 CLIENT -> SERVER: EHLO localhost 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "" 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250-mx.google.com at your service, [81.191.67.35] " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "250-mx.google.com at your service, [81.191.67.35] " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250-SIZE 35882577 " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250-8BITMIME " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250-STARTTLS " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250-PIPELINING " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250-CHUNKING " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "250 SMTPUTF8 " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 " 2015-01-08 17:25:59 SERVER -> CLIENT: 250-mx.google.com at your service, [81.191.67.35] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8 2015-01-08 17:25:59 CLIENT -> SERVER: STARTTLS 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "" 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "220 2.0.0 Ready to start TLS " 2015-01-08 17:25:59 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS 
Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Applications/XAMPP/xamppfiles/htdocs/Nettside-til-pappa/PHPMailer/class.smtp.php on line 338 
2015-01-08 17:25:59 CLIENT -> SERVER: QUIT 2015-01-08 17:25:59 SMTP -> get_lines(): $data was ""  2015-01-08 17:25:59 SMTP -> get_lines(): $str is "MIAf�5*:�u���\^� N�\��� 6��I���f�~���xA�ٿ��xb㕈��7�q�-��� �O���䳽�q]��g��J�n�t��5E�mq���cC�MH��UHTv��B������/Dj���#m+��^����}�ui�q- �[�V#eP&�H�y>J>1'���D�/�l�37�4�G�PkU�f���&�4wlON��i��aX����-崟�{��w��Eu�P;�]ʪ���~6����.;v " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "MIAf�5*:�u���\^� N�\��� 6��I���f�~���xA�ٿ��xb㕈��7�q�-��� �O���䳽�q]��g��J�n�t��5E�mq���cC�MH��UHTv��B������/Dj���#m+��^����}�ui�q- �[�V#eP&�H�y>J>1'���D�/�l�37�4�G�PkU�f���&�4wlON��i��aX����-崟�{��w��Eu�P;�]ʪ���~6����.;v " 2015-01-08 17:25:59 SMTP -> get_lines(): $data was "MIAf�5*:�u���\^� N�\��� 6��I���f�~���xA�ٿ��xb㕈��7�q�-��� �O���䳽�q]��g��J�n�t��5E�mq���cC�MH��UHTv��B������/Dj���#m+��^����}�ui�q- �[�V#eP&�H�y>J>1'���D�/�l�37�4�G�PkU�f���&�4wlON��i��aX����-崟�{��w��Eu�P;�]ʪ���~6����.;v " 2015-01-08 17:25:59 SMTP -> get_lines(): $str is "~���" ��r���$N��jd&�F�D|:�D�~��Fv�����X�܂�*19d�> " 2015-01-08 17:25:59 SMTP -> get_lines(): $data is "MIAf�5*:�u���\^� N�\��� 6��I���f�~���xA�ٿ��xb㕈��7�q�-��� �O���䳽�q]��g��J�n�t��5E�mq���cC�MH��UHTv��B������/Dj���#m+��^����}�ui�q- �[�V#eP&�H�y>J>1'���D�/�l�37�4�G�PkU�f���&�4wlON��i��aX����-崟�{��w��Eu�P;�]ʪ���~6����.;v ~���" ��r���$N��jd&�F�D|:�D�~��Fv�����X�܂�*19d�> " 2015-01-08 17:25:59 SERVER -> CLIENT: MIAf�5*:�u���\^� N�\��� 6��I���f�~���xA�ٿ��xb㕈��7�q�-��� �O���䳽�q]��g��J�n�t��5E�mq���cC�MH��UHTv��B������/Dj���#m+��^����}�ui�q- �[�V#eP&�H�y>J>1'���D�/�l�37�4�G�PkU�f���&�4wlON��i��aX����-崟�{��w��Eu�P;�]ʪ���~6����.;v ~���" ��r���$N��jd&�F�D|:�D�~��Fv�����X�܂�*19d�> 2015-01-08 17:25:59 SMTP ERROR: QUIT command failed: MIAf�5*:�u���\^� N�\��� 6��I���f�~���xA�ٿ��xb㕈��7�q�-��� �O���䳽�q]��g��J�n�t��5E�mq���cC�MH��UHTv��B������/Dj���#m+��^����}�ui�q- �[�V#eP&�H�y>J>1'���D�/�l�37�4�G�PkU�f���&�4wlON��i��aX����-崟�{��w��Eu�P;�]ʪ���~6����.;v ~���" ��r���$N��jd&�F�D|:�D�~��Fv�����X�܂�*19d�> 2015-01-08 17:25:59 Connection: closed 2015-01-08 17:25:59 SMTP connect() failed. bool(false) 
+0

你肯定端口是587? –

+0

此外,它似乎smtp.google.com不是一个有效的主机名... –

+0

你是否谷歌的错误代码?这可以帮助你:http://davidwalsh.name/php-ssl-curl-error –

回答

0

try to change following things:

$mail->Port = 465; //port number 
$mail->SMTPSecure = 'ssl'; //smtp secure 
$mail->setFrom('[email protected]', 'Sindre Moldeklev'); //set from accept two parameters 
$mail->SMTPAuth = true; //smtp auth 
+0

我试过了,并且错误消息缩短了很多,但我仍然无法连接。 –

+0

@SindreMoldeklev现在出现什么错误? – Priyank

+0

这是现在的错误消息:SSL加载2015-01-08 17:54:24 \t连接:打开到ssl://smtp.gmail.com:465,t = 300,opt = array()2015-01- 08 17:54:24 \t SMTP错误:无法连接到服务器:(0)2015-01-08 17:54:24 \t SMTP连接()失败。 bool(false) –

0

试着改变你的主机到“localhost” 的

+0

这不提供问题的答案。要批评或要求作者澄清,在他们的帖子下留下评论 - 你总是可以评论你自己的帖子,一旦你有足够的[声誉](http://stackoverflow.com/help/whats-reputation),你会能够[评论任何帖子](http:// stackoverflow。COM /帮助/权限/评论)。 –

+0

我只是想帮忙。我的帖子怎么没有试图回答这个问题? – jpineds

+0

我没有说你不是在帮助,但以上是评论,并不是真正的答案。 –