我试图通过smtp.gmail.com使用PHPMailer插件发送邮件。发送在我的本地计算机上工作正常,但当我使用我的远程服务器时,它会延迟发送,通常大约30秒。
function sendAuthEmail($subject, $mail_body, $mailTo, $mailToTitle, $mailFrom, $fromTitle)
{
require 'PhpMailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->Username = 'no-reply@domail.com';
$mail->Password = 'password';
$mail->AddReplyTo($mailFrom, $fromTitle);
$mail->SetFrom($mail->Username, 'Domain.com');
$mail->AddAddress($mailTo, $mailToTitle);
$mail->CharSet = 'UTF-8';
$mail->Subject = $subject;
$mail->MsgHTML($mail_body);
if($mail->Send()) {
return;
} else {
die('There was an error: '.$mail->ErrorInfo.'</i>');
}
}
但是当我尝试使用gethostbyname(&#39; smtp.gmail.com&#39;)时,它失败并显示以下调试信息:
2016-11-23 12:36:11 SERVER -> CLIENT: 220 smtp.gmail.com ESMTP a47sm16079918qtc.17 - gsmtp
2016-11-23 12:36:11 CLIENT -> SERVER: EHLO www.sellercloud.com
2016-11-23 12:36:11 SERVER -> CLIENT: 250-smtp.gmail.com at your service, [199.189.62.92] 250-SIZE 35882577 250-8BITMIME 250-STARTTLS 250-ENHANCEDSTATUSCODES 250-PIPELINING 250-CHUNKING 250 SMTPUTF8
2016-11-23 12:36:11 CLIENT -> SERVER: STARTTLS
2016-11-23 12:36:11 SERVER -> CLIENT: 220 2.0.0 Ready to start TLS
2016-11-23 12:36:11 SMTP Error: Could not connect to SMTP host.
2016-11-23 12:36:11 CLIENT -> SERVER: QUIT
2016-11-23 12:36:11 SERVER -> CLIENT:
2016-11-23 12:36:11 SMTP ERROR: QUIT command failed:
2016-11-23 12:36:11 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
答案 0 :(得分:0)
服务器问题证明是DNS解决问题。 PHP邮件程序无法正确解析smtp.gmail.com,这就是为什么没有一个已知的修复工作的邮件原因。
如果您遇到类似问题,检查您的DNS服务器。