问题
In contact form it's working fine in localhost. While hosted it's not working. Showing the error
**"SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: xxxxx@gmail.com ERROR"**
I attached my contact_submit.php code form
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;
}
I'm using phpmailer 5.2.1.
I contacted the hosting side, but i'm not getting actual response.
回答1:
I believe you have to connect to smtp.gmail.com on port 465, not port 587. Also, SSL is required. So, you should have:
$mail->Host = "smtp.gmail.com";
$mail->Port = 465;
$mail->SMTPSecure = "ssl";
回答2:
You can increase the time out by prepending your code with:
set_time_limit(3600);
and then specifying the Timeout of the $mail
object as such:
$mail->Timeout = 3600;
回答3:
I had a similar problem, with mail being sent correctly from my local server but not my live one on the internet. It turned out my host (Bluehost) blocked outgoing connections on port 465.
I found a wonderful how-to which fixed it for me:
- In your cPanel > Mail, find the MX (MX Entry) section, and select 'remote mail exchanger'.
- In the cPanel email accounts section, create the appropriate email address (don't skip this)
- Don't use "smtp.live.com" as your smtp host. Use the smtp host of your Shared Linux Hosting smtp. I don't know how you will get yours. Mine is boxXXXX.bluehost.com.
- Set your username and password to be the same as the email account you just set-up in cPanel.
来源:https://stackoverflow.com/questions/22832410/smtp-error-failed-to-connect-to-server-connection-timed-out-110-the-follo