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 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?