PHPMailer 脚本在共享服务器中运行良好,但相同的脚本在 AWS 服务器中不起作用

穆楚尔

我有 2 个网站:AWS 中的https://www.nubeduc.cl/便宜的共享主机中的http://www.nubeduc.com/我使用 PHPMailer 的脚本发送电子邮件,但该脚本仅适用于 nubeduc.com 在两台服务器中,今天下载的 PHPMailer 文件都在文件夹 src(http://www.nubeduc.com/scr/https://www .nu​​beduc.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 = '[email protected]';
//Password to use for SMTP authentication
$mail->Password = 'mypassword';
//Set who the message is to be sent from
$mail->setFrom('[email protected]', 'Nubeduc Plataforma');
//Set an alternative reply-to address
$mail->addReplyTo('[email protected]', 'Nubeduc Contacto');
//Set who the message is to be sent to
$mail->addAddress('***my_email***@gmail.com', 'My Name');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
$mail->Body = "Hurray! \n\n Great.";
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');

//send the message, check for errors
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo 'Message sent from NUBEDUC to stack overflow guys!';
}

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

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 站点中不起作用?请帮忙!!!

同步

AWS 正在阻止您的出站 SMTP。这很常见,并且是与配置安全组不同的问题。AWS 真的希望您使用他们自己的邮件服务器和他们的 SES 服务进行中继,但此支持文档描述了如何解除此限制。它说:

默认情况下,Amazon EC2 限制所有 EC2 实例的端口 25 上的流量,但您可以请求取消此限制。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章