![](/img/trans.png)
[英]SMTP -> ERROR: Failed to connect to server: Connection timed out (110)
[英]SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: xxxxx@gmail.com ERROR
在联系表中,它在localhost中可以正常工作。 托管时无法正常工作。 显示错误
**"SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: xxxxx@gmail.com ERROR"**
我附上了contact_submit.php代码表
include_once('class.phpmailer.php');
$mail->IsSMTP(); //
$mail->Host = "smtp.gmail.com";
$mail->SMTPDebug = 1;
$mail->SMTPAuth = true;
$mail->Host = "smtp.gmail.com";
$mail->Port = 587;
$mail->Username = "xxxx@gmail.com";
$mail->Password = "xxxx@123";
$mail->SMTPSecure = "tls";
$mail->SetFrom($email, $name);
$mail->AddReplyTo($email,$name);
$mail->Subject = "Contact - xxx";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!";
$mail->MsgHTML($body);
$mail->AddAddress("xxx@gmail.com","xxx");
if(!$mail->Send())
{
echo $mail;
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=contact.php?id='.$id.'&send=success">';
exit;
}
我正在使用phpmailer 5.2.1。
我联系了托管方,但没有得到实际答复。
我相信您必须在端口465而不是端口587上连接到smtp.gmail.com。此外,还需要SSL。 因此,您应该具有:
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
我遇到了类似的问题,邮件是从本地服务器正确发送的,而不是从Internet发送的实时邮件。 原来,我的主机(Bluehost)阻止了端口465上的传出连接。
我找到了一个很棒的方法来为我解决:
您可以通过在代码前添加以下代码来增加超时时间:
set_time_limit(3600);
然后指定$mail
对象的超时,如下所示:
$mail->Timeout = 3600;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.