无法让 PHPMailer 工作


Can't get PHPMailer to work

所以我正在尝试让 PHPMailer 工作,我已经下载了最新版本并根据文档对其进行了配置,我尝试了 telnet smtp.gmail.com 587 来检查我是否可以达到低谷并且有效,我已经尝试了 ping smtp.gmail.com 并且有效,我已经禁用了来自 Google 的两步身份验证,并且我已经完成了验证码验证。我还在 Google 安全设置中开启了应用的访问权限。我已经尝试过使用 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 优胜美地 v. 10.10.1 上通过 xaamp 运行它。我还取消了来自 php.ini 的扩展名=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)

尝试更改以下内容:

$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

尝试将主机更改为"本地主机"