无法让PHPMailer工作

时间:2015-01-08 17:35:10

标签: php phpmailer

所以我试图让PHPMailer工作,我已经下载了最新版本并根据文档进行了配置,我已经尝试过telnet smtp.gmail.com 587来检查我是否可以获得低谷并且有效,我有尝试过ping smtp.gmail.com并且有效,我已经禁用了谷歌的两步验证,我已经通过了验证码验证。我还在谷歌安全设置中开启了对应用的访问权限。我尝试过ssl和tls,但无论我尝试什么,我仍然得到

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 = 'mymail@gmail.com';
$mail->Password = 'mypassword';


$mail->From = 'sndrem@gmail.com';
$mail->FromName = 'Sindre Moldeklev';
$mail->addReplyTo('mymail@gmail.com', 'Reply adress');
$mail->addAddress('somemail@live.no', '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,这样就可以了。

让我疯狂,不让它发挥作用。我试图在iMac 27“osx Yosemite v.10.10.1上通过xaamp运行它。我还从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)

2 个答案:

答案 0 :(得分:0)

  

尝试改变以下事项:

$mail->Port = 465;  //port number
$mail->SMTPSecure = 'ssl';  //smtp secure
$mail->setFrom('sndrem@gmail.com', 'Sindre Moldeklev'); //set from accept two parameters
$mail->SMTPAuth = true;  //smtp auth

答案 1 :(得分:0)

尝试将您的主机更改为&#34; localhost&#34;