SMTP错误:无法连接到SMTP主机

anv*_*nvd 4 php smtp phpmailer

我有这个代码,一切都在我的本地服务器上运行良好.电子邮件发送没有任何问题.

但现在我将内容传递给网络服务器,我收到了这个错误......

SMTP Error: Could not connect to SMTP host.
Run Code Online (Sandbox Code Playgroud)

SSL在服务器中启用..正确吗?那么,问题是什么? 在此输入图像描述

            $mail = new PHPMailer();
            $mail->IsSMTP();
            $mail->SMTPAuth   = true;                  // enable SMTP authentication
            $mail->SMTPSecure = "ssl";                 // sets the prefix to the servier
            $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
            $mail->Port       = 465;                   // set the SMTP port
            $mail->Username   = "dnteiro"; // GMAIL username
            $mail->Password   = "xxx";      // GMAIL password
Run Code Online (Sandbox Code Playgroud)

AJ.*_*AJ. 8

听起来你的网络主机正在阻止与smtp.gmail.com:465的出站连接.建议:

  1. 验证:如果您具有对您的Web托管服务器的shell /终端访问权限,请尝试使用telnet测试来验证它们实际上阻止了这一点.跑telnet smtp.gmail.com 465

  2. 联系人:致电或发送电子邮件给您的托管服务提供商,了解他们为出站中继提供的SMTP服务器.确保他们知道您要将您的@gmail.com地址用作发件人/回复地址.

  3. 更新代码:主机为您提供其他邮件服务器后,请更新代码并重试.

如果您的Web主机根本不允许从其服务器进行出站中继,那么您需要查看交换主机(如果这是您的应用程序的要求).

  • 我面临同样的问题,telnet实际上正在为我工​​作.所以我的主持人并没有阻止我通过465端口接触smtp.gmail.com.有什么建议吗? (2认同)