php SMTP -> 错误:无法连接到服务器:连接超时(110)以下发件人地址失败:[email protected] 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22832410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:18:12  来源:igfitidea点击:

SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: [email protected] ERROR

phpemailsmtpphpmaileroutgoing-mail

提问by user3492847

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: [email protected] ERROR"** 

I attached my contact_submit.php code form

我附上了我的 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   = "[email protected]"; 
    $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("[email protected]","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.

我正在使用 phpmailer 5.2.1。

I contacted the hosting side, but i'm not getting actual response.

我联系了托管方,但没有得到实际答复。

回答by mti2935

I believe you have to connect to smtp.gmail.com on port 465, not port 587. Also, SSL is required. So, you should have:

我相信您必须通过端口 465 而不是端口 587 连接到 smtp.gmail.com。此外,还需要 SSL。所以,你应该有:

$mail->Host       = "smtp.gmail.com";      
$mail->Port       = 465;                   
$mail->SMTPSecure = "ssl";                 

回答by Kit Johnson

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.

我有一个类似的问题,邮件从我的本地服务器正确发送,但不是我在互联网上的实时服务器。结果我的主机(Bluehost)阻止了端口 465 上的传出连接。

I found a wonderful how-towhich fixed it for me:

我找到了一个很好的方法来为我修复它:

  1. In your cPanel > Mail, find the MX (MX Entry) section, and select 'remote mail exchanger'.
  2. In the cPanel email accounts section, create the appropriate email address (don't skip this)
  3. 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.
  4. Set your username and password to be the same as the email account you just set-up in cPanel.
  1. 在您的 cPanel > Mail 中,找到 MX(MX Entry)部分,然后选择“远程邮件交换器”。
  2. 在 cPanel 电子邮件帐户部分,创建适当的电子邮件地址(不要跳过)
  3. 不要使用“smtp.live.com”作为您的 smtp 主机。使用您的 Shared Linux Hosting smtp 的 smtp 主机。我不知道你将如何得到你的。我的是 boxXXXX.bluehost.com。
  4. 将您的用户名和密码设置为与您刚刚在 cPanel 中设置的电子邮件帐户相同。

回答by Altair CA

You can increase the time out by prepending your code with:

您可以通过在代码前添加以下内容来增加超时时间:

set_time_limit(3600);

and then specifying the Timeout of the $mailobject as such:

然后指定$mail对象的超时如下:

$mail->Timeout = 3600;