SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting相关的知识,希望对你有一定的参考价值。
2018-03-05 18:25:08服务器 - >客户端:220 smtp.gmail.com ESMTP o5sm27821483pfh.51 - gsmtp 2018-03-05 18:25:08客户端 - >服务器:EHLO localhost 2018-03-05 18 :25:08服务器 - >客户:250-smtp.gmail.com为您服务,[43.247.156.6] 250-SIZE 35882577250-8BITMIME250-STARTTLS250-ENHANCEDSTATUSCODES250-PIPELINING250-CHUNKING250 SMTPUTF8 2018-03-05 18:25:08客户端 - >服务器:STARTTLS 2018-03-05 18:25:08服务器 - >客户端:220 2.0.0准备启动TLS SMTP错误:无法连接到SMTP主机。 2018-03-05 18:25:09客户端 - >服务器:退出2018-03-05 18:25:09 2018-03-05 18:25:09 SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting消息已发送
我的代码是
<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailerPHPMailerPHPMailer;
use PHPMailerPHPMailerException;
//Load composer's autoloader
require 'vendor/autoload.php';
$mail = new PHPMailer(); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'girish8134@gmail.com'; // SMTP username
$mail->Password = '*****'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('girish8134@gmail.com', 'Giri');
$mail->addAddress('girish3055@gmail.com', 'giri3055'); // Add a recipient
//Content
$mail->ishtml(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message bod';
$mail->AltBody = 'This is the body is';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo;
}
首先尝试这个> https://support.google.com/accounts/answer/1064203?hl=en禁用两步验证。
如果它不起作用,你总是可以尝试简化一些代码(并尝试ssl - port 467
):
$mail->setFrom('girish8134@gmail.com');
$mail->addAddress('girish3055@gmail.com');
让我知道它是否有效。
以上是关于SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting的主要内容,如果未能解决你的问题,请参考以下文章
PHPMailer发送邮件失败:SMTP connect() failed.
smtplib.SMTP starttls 因 tlsv1 警报解码错误而失败
Connection could not be established with host smtp.163.com [Connection timed out #110]