douyao2529 2017-12-09 23:59
浏览 62

SMTP错误:无法使用localhost XAMPP中的phpmailer 6.0连接到服务器

I'm trying to send mail using phpmailer 6.0. I updated my php version and I made my mail "verify less secure apps " because I'm using gmail.

I get an error like this:

2017-12-09 23:30:09 SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

I'm using sample code from the readme file.

<?php 
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;

require 'PHPMailer-master/src/PHPMailer.php';
require 'PHPMailer-master/src/SMTP.php';
require 'PHPMailer-master/src/Exception.php';

$mail =  new PHPMailer(true);                     
try {

$mail->SMTPDebug = 2;                                 
$mail->isSMTP();                                      
$mail->Host = 'smtp.gmail.com';  
$mail->SMTPAuth = true;                               
$mail->Username = 'username@gmail.com';                 
$mail->Password = 'password';                           
$mail->SMTPSecure = 'ssl';                            
$mail->Port = 465;                                    
$mail->setFrom('username@gmail.com');
$mail->addAddress('username@gmail.com');     

$mail->isHTML(true);                                  
$mail->Subject = 'hello';
$mail->Body    = 'dasdasd';
$mail->AltBody = 'dasdasd';

$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
    echo 'Message could not be sent.';
    echo 'Mailer Error: ' . $mail->ErrorInfo;
}
 ?>

*note I am not using composer because there isn't any vendor folder when I download the phpmailer.

  • 写回答

1条回答 默认 最新

  • douwen5681 2017-12-10 08:24
    关注

    this is the error when i'm using smtp debug =3

    2017-12-10 08:22:52 Connection: opening to ssl://smtp.gmail.com:465, timeout=300, options=array() 2017-12-10 08:22:52 Connection failed. Error #2: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed [D:\Software\XAMPP\htdocs\check334\PHPMailer-master\src\SMTP.php line 325] 2017-12-10 08:22:52 Connection failed. Error #2: stream_socket_client(): Failed to enable crypto [D:\Software\XAMPP\htdocs\check334\PHPMailer-master\src\SMTP.php line 325] 2017-12-10 08:22:52 Connection failed. Error #2: stream_socket_client(): unable to connect to ssl://smtp.gmail.com:465 (Unknown error) [D:\Software\XAMPP\htdocs\check334\PHPMailer-master\src\SMTP.php line 325] 2017-12-10 08:22:52 SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

    评论

报告相同问题?

悬赏问题

  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿