简体   繁体   English

SMTP 错误:无法连接到服务器:使用 phpmailer 时连接超时(110)

[英]SMTP ERROR: Failed to connect to server: Connection timed out (110) when using phpmailer

This works perfectly in my old server.这在我的旧服务器中完美运行。

2020-07-18 16:37:45 SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed. 2020-07-18 16:37:45 SMTP 错误:无法连接到服务器:连接超时 (110) SMTP 连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting I am now using CentOS 7 and php7.3.2 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting我现在正在使用 CentOS 7 和 php7.3.2

What I've tried.我试过的。

  • use port 587,465,25使用端口 587,465,25
  • use host smtp.gmail.com,108.177.122.108使用主机 smtp.gmail.com,108.177.122.108

This is my code:这是我的代码:

<?php
require_once "config.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
if($_SERVER["REQUEST_METHOD"] == "POST"){
    $randompassword = generateRandomString();
    $email = $_POST['email'];
    $mail = new PHPMailer(true);
    try {
        $connect->query("SET NAMES 'utf8'");
        $insertSql = "INSERT INTO users (username, password, email, forgot) VALUES ('$name', '$randompassword', '$email', 1)";
        $status = $connect->query($insertSql);
        $mail->isSMTP();                                            // Send using SMTP
        $mail->SMTPAuth   = true;
        $mail->Host       = 'smtp.gmail.com';                    // Set the SMTP server to send through
        $mail->SMTPAuth   = true;                                   // Enable SMTP authentication
        $mail->Username   = 'username@gmail.com';                     // SMTP username
        $mail->Password   = '*******';                               // SMTP password
        $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;         // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` encouraged
        $mail->Port       = 587;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above
        $mail->Charset    = "UTF-8";
        $mail->setFrom('username@gmail.com', 'Mailer');
        $mail->addAddress($email);               // Name is optional
        $mail->addReplyTo('to@gmail.com', 'to');                                 // Set email format to HTML
        $mail->Subject = 'subject';
        $mail->Body    = 'body'
        $mail->send();
        echo '<script>alert("already send");</script>'; 
    } 
    catch (Exception $e) {
        echo "<script>alert('error');</script>";
        echo !extension_loaded('openssl')?"Not Available":"Available";
        exit;
    }
}
?>

UPDATE更新

I test telnet smtp.gmail.com for port 25 465 587,the result is also connection time out.Then I test on my computer gets a normal result.我测试了端口 25 465 587 的 telnet smtp.gmail.com,结果也是正常的连接超时。

I'm using a Linode Server, they blocked port 25, 465, 587, so I can't send mail and telnet smtp.gmail.com.我正在使用 Linode 服务器,他们阻止了端口 25、465、587,所以我无法发送邮件和远程登录 smtp.gmail.Z4D236D9A2D102C50FE6AD1C5ZDAB4。 for more infomation, ckick here. 如需更多信息,请点击此处。

Network problem.网络问题。 Firewall is blocking those ports.防火墙正在阻止这些端口。 Surprised it's blocking the SSL port as well.令人惊讶的是它也阻塞了 SSL 端口。 Once you resolve that, you should be good to go.一旦你解决了这个问题,你应该对 go 很好。 As an alternative, you could change the port on the SMTP server to a custom port that your provider will allow you to use (25000, 25252, etc).作为替代方案,您可以将 SMTP 服务器上的端口更改为您的提供商允许您使用的自定义端口(25000、25252 等)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PHPMailer的臭名昭著的SMTP错误:无法连接到服务器:连接超时(110)SMTP connect()失败 - PHPMailer's infamous SMTP ERROR: Failed to connect to server: Connection timed out (110) SMTP connect() failed PHPMailer SMTP无法连接到服务器:连接超时(110)到Gmail - PHPMailer SMTP Failed to connect to server: Connection timed out (110) to Gmail SMTP错误:无法连接到服务器:使用PHPMailer和Outlook SMTP连接超时(110) - SMTP ERROR: Failed to connect to server: Connection timed out (110) with PHPMailer and Outlook SMTP SMTP-&gt;错误:无法连接到服务器:连接超时(110) - SMTP -> ERROR: Failed to connect to server: Connection timed out (110) SMTP-&gt;错误:无法连接到服务器:连接超时(110)SMTP错误:无法连接到SMTP主机。 - SMTP -> ERROR: Failed to connect to server: Connection timed out (110) SMTP Error: Could not connect to SMTP host. 无法连接到服务器:连接超时(110)SMTP Connect()失败。 邮件未发送。邮件错误:SMTP Connect()失败 - Failed to connect to server: Connection timed out (110)SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed SMTP-&gt;错误:无法连接到服务器:连接超时(110)以下“发件人”地址失败:xxxxx@gmail.com错误 - SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: xxxxx@gmail.com ERROR 通过Laravel使用gmail smtp:[连接超时#110] - Using gmail smtp via Laravel: [Connection timed out #110] PHPMailer 错误:SMTP -&gt; 错误:无法连接到服务器 - PHPMailer error: SMTP -> ERROR: Failed to connect to server PHPMailer SMTP错误:无法连接到服务器 - PHPMailer SMTP ERROR: Failed to connect to server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM