PHPMailer 脚本在共享服务器中工作正常,但相同的脚本在 AWS 服务器中不起作用

我有 2 个网站:AWS中的https://www.nubeduc.cl/和更便宜的共享主机中的http://www.nubeduc.com/。我使用 PHPMailer 的脚本来发送电子邮件,但是这个脚本只适用于 nubeduc.com 在这两个服务器中,今天下载的 PHPMailer 文件都在文件夹 src 中(http://www.nubeduc.com/scr/https://www .nubeduc.cl/scr/)我创建了一个名为“smtp.php”的php文件用于测试目的:(http://www.nubeduc.com/smtp.phphttps://www.nubeduc.cl/smtp。 php )

<?php

/**

 * This example shows making an SMTP connection with authentication.

 */


//Import the PHPMailer class into the global namespace

use PHPMailer\PHPMailer\PHPMailer;

use PHPMailer\PHPMailer\SMTP;


//SMTP needs accurate times, and the PHP time zone MUST be set

//This should be done in your php.ini, but this is how to do it if you don't have access to that

date_default_timezone_set('Etc/UTC');


require 'src/PHPMailer.php';

require 'src/SMTP.php';


//Create a new PHPMailer instance

$mail = new PHPMailer;

//Tell PHPMailer to use SMTP

$mail->isSMTP();

//Enable SMTP debugging

// SMTP::DEBUG_OFF = off (for production use)

// SMTP::DEBUG_CLIENT = client messages

// SMTP::DEBUG_SERVER = client and server messages

$mail->SMTPDebug = SMTP::DEBUG_LOWLEVEL;

//Set the hostname of the mail server

$mail->Host = 'mail.nubeduc.com';

//Set the SMTP port number - likely to be 25, 465 or 587

$mail->Port = 25;

//Whether to use SMTP authentication

$mail->SMTPAuth = true;

//Username to use for SMTP authentication

$mail->Username = 'mailer@nubeduc.com';

//Password to use for SMTP authentication


当我在 nubeduc.com 中运行这个脚本时,它的工作就像一个魅力。您可以尝试检查调试日志。但是当我在 110 秒后在 nubeduc.cl 中运行时,会在屏幕上显示这些错误:


2020-03-04 20:25:20 Connection: opening to mail.nubeduc.com:25, timeout=300, options=array()

2020-03-04 20:27:30 Connection failed. Error #2: stream_socket_client(): unable to connect to mail.nubeduc.com:25 (Connection timed out) [/var/www/nubeduc.cl/src/SMTP.php line 349]

2020-03-04 20:27:30 SMTP ERROR: Failed to connect to server: Connection timed out (110)

现在我更新了 Ubuntu 实例,检查 php openssl 扩展(处于活动状态),但没有任何效果。为什么该脚本在我的 AWS 站点中不起作用?请帮忙!!!


DIEA
浏览 101回答 1
1回答

噜噜哒

AWS 正在阻止您的出站 SMTP。这很常见,是与配置安全组不同的问题。AWS 确实希望您使用他们自己的邮件服务器和他们的 SES 服务进行中继,但是这个支持文档描述了如何解除这个限制。它说:默认情况下,Amazon EC2 会限制所有 EC2 实例的端口 25 上的流量,但您可以请求取消此限制。
打开App,查看更多内容
随时随地看视频慕课网APP