0
我遇到与SMTP connect() failed PHPmailer - PHP相同的问题。我的代码如下:如何用PHP发送电子邮件
public function sendEmail($toAddress, $subject, $message)
{
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'username';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->SMTPDebug = 2;
$mail->Port = 587;
$mail->setFrom('[email protected]', 'Tripmatcher Support');
$mail->addAddress($toAddress);
$mail->Subject = $subject;
$mail->Body = $message;
if (!$mail->send()) {
error_log('Mailer Error: ' . $mail->ErrorInfo);
} else {
error_log('Email has been sent.');
}
}
两个问题:
- 这里有什么问题,据我可以看到我的代码看起来是正确的,而且我也启用不够安全的应用我的电子邮件地址?
- [Mon Sep 18 21:01:43.342766 2017] [:error] [pid 22052] [client 2.28.76.119:55132]邮件错误:SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting,referer:
这就是我在日志中看到的所有内容,如何才能生成更具描述性的错误消息?我曾试着寻找类似的问题,但我仍然无法弄清楚究竟是什么问题。
您是否阅读过您在问题中提到的页面?特别是https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#smtp-error-could-not-connect-to-smtp-host和https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting#enabling -debug-output部分 – Nima
dig + short smtp.gmail.com gmail-smtp-msa.l.google.com。 64.233.184.108 64.233.184.109 –
这就是我从dig + short smtp.gmail.com得到的结果,而且我的SSL不适用于GoDaddy,所以我不认为它是这两者之一。 –