【发布时间】:2017-10-08 09:39:57
【问题描述】:
在此脚本完美运行之前,我在过去三天就遇到了这个问题。现在出现错误:
SMTP 错误:无法连接到服务器:(0) 2017-10-06 21:05:34 SMTP connect() 失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 邮件未发送。邮件程序错误:SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting ahsanazhar12@gmail.com
这是我的脚本:
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$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 = 'example@gmail.com'; // SMTP username
$mail->Password = 'mypassword'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;
$mail->setFrom('example@gmail.com', 'Your Name');
$mail->addAddress('example@gmail.com', 'My Friend');
$mail->Subject = 'First PHPMailer Message';
$mail->Body = 'Hi! This is my first e-mail sent through PHPMailer.';
if (!$mail->send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
我认为 Gmail 可能更改了使用 SMTP 或类似方式发送电子邮件的设置。
【问题讨论】:
-
这是一个疯狂的想法 - 尝试点击错误消息中的链接,它会告诉您有关此问题的所有信息以及如何解决它。
标签: php email phpmailer mailer