PHPMailer SMTP连接失败错误 [英] PHPMailer SMTP connection failed error

查看:103
本文介绍了PHPMailer SMTP连接失败错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的代码中,我只是尝试使用PhPmailer工具将电子邮件发送给收件人,但是每次我都会收到错误消息.我已经看了很多有关此的视频教程,并且看了无数的网站,但没有解决方法.我尝试将端口从"587更改为465",更改"SMTPDebug = 2"以查看明确的错误消息,甚至尝试从github页面进行故障排除,但我仍然没有运气.这是我的代码

In my code I am just trying to send an email to a recipient using the PhPmailer tool but every time I do i get errors. I've watched numerous amounts of video tutorials on this and looked at tons of websites but no fix. I've tried changing my port from "587 to 465", change the "SMTPDebug = 2" to see clear error message, I even tried troubleshooting from the github page but I am still having no luck. Here is my code

<?php
require 'PHPMailerAutoload.php';
require 'credential.php';

$mail = new PHPMailer;

$mail->SMTPDebug = 4;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp1.gmail.com;';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = EMAIL;                 // SMTP username
$mail->Password = PASS;                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to

$mail->setFrom(EMAIL, 'Testing this');
$mail->addAddress('testemail123@outlook.com');     // Add a recipient              // Name is optional
$mail->addReplyTo(EMAIL);
$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

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

错误消息

2018-02-23 07:16:07 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ()
2018-02-23 07:16:07 Connection: opened
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "220 smtp.gmail.com ESMTP s125sm758477vkb.40 - gsmtp"
2018-02-23 07:16:07 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP s125sm758477vkb.40 - gsmtp
2018-02-23 07:16:07 CLIENT -> SERVER: EHLO localhost
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-smtp.gmail.com at your service, [x.x.x.x]"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-SIZE 35882577"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-8BITMIME"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-STARTTLS"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-ENHANCEDSTATUSCODES"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-PIPELINING"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250-CHUNKING"
2018-02-23 07:16:07 SMTP -> get_lines(): $data is "250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING"
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "250 SMTPUTF8"
2018-02-23 07:16:07 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [x.x.x.x]250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8
2018-02-23 07:16:07 CLIENT -> SERVER: STARTTLS
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07 SMTP -> get_lines(): $str is "220 2.0.0 Ready to start TLS"
2018-02-23 07:16:07 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2018-02-23 07:16:07 Connection failed. Error #2: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed [C:\wamp64\www\mailer\phpmailer\class.smtp.php line 375]
SMTP Error: Could not connect to SMTP host.
2018-02-23 07:16:07 CLIENT -> SERVER: QUIT
2018-02-23 07:16:07 SMTP -> get_lines(): $data is ""
2018-02-23 07:16:07 
2018-02-23 07:16:07 
2018-02-23 07:16:07 
2018-02-23 07:16:07 
2018-02-23 07:16:07 
2018-02-23 07:16:07 Connection: closed
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

推荐答案

您将收到一个DNS错误,提示它找不到主机名.因此,请查看您的主机名属性,并在应为smtp.gmail.com时看到它包含smtp1.gmail.com.

You are getting a DNS error that says it can’t find the host name. So look at your host name property, and see it contains smtp1.gmail.com when it should be smtp.gmail.com.

这篇关于PHPMailer SMTP连接失败错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆