AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-798660

Emon Hoque's questions

Martin Hope
Emon Hoque
Asked: 2021-08-15 23:27:32 +0800 CST

使用 SwiftMailer 发送电子邮件时,Digital Ocean 出现错误 500

  • 0

当联系表格提交到我的网站时,我正在尝试从我的辅助电子邮件地址向我的主电子邮件地址发送一封电子邮件。我正在使用Swiftmailer来实现这一点。当我在计算机上的 XAMPP 服务器上脱机使用该代码时,该代码运行良好,但是当我尝试在运行 LAMP 堆栈的 Digital Ocean Droplet 上运行它时,这与我的脱机设置几乎相同,它不起作用并返回错误 500。

我调查了一下,结果发现,SMTP 被禁用以防止垃圾邮件,如果我联系支持,它可以被解除。在我联系他们之后,他们告诉我他们无法解除对端口 25 的限制,但告诉我尝试其他端口,并且 SMTP 不适用于浮动 IP。我删除了我的浮动 IP 来帮助解决这个问题,我目前正在尝试将端口 578 与 Hotmail 电子邮件地址一起使用,但它仍然无法正常工作。

到目前为止我已经尝试过:

我使用此命令打开了 Digital Ocean Support 建议的 587端口。

sudo iptables -A INPUT -p tcp --dport 587 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 587 -m conntrack --ctstate ESTABLISHED -j ACCEPT

之后,我的服务器就可以在 587 端口连接到 smtp.office365.com,如下面的命令所示:

nc -vz smtp.office365.com 587
Connection to smtp.office365.com 587 port [tcp/submission] succeeded!

命令“ufw status”显示端口 587 在 ipv4 和 ipv6 上都是打开的:

To                         Action      From
--                         ------      ----
22/tcp                     LIMIT       Anywhere
80/tcp                     ALLOW       Anywhere
443/tcp                    ALLOW       Anywhere
3306/tcp                   ALLOW       Anywhere
587/tcp                    ALLOW       Anywhere
22/tcp (v6)                LIMIT       Anywhere (v6)
80/tcp (v6)                ALLOW       Anywhere (v6)
443/tcp (v6)               ALLOW       Anywhere (v6)
3306/tcp (v6)              ALLOW       Anywhere (v6)
587/tcp (v6)               ALLOW       Anywhere (v6)

但是,当我尝试运行联系表单时,它最终无法在 droplet 上运行,而它确实可以离线运行,并且我按预期收到了电子邮件。

有什么我想念的吗?

我将在下面附上我的 swiftmailer 部分的代码,以防它有助于识别我似乎遗漏的代码中的任何潜在错误。

include_once 'private/pass.inc.php';


//These fields usually get the data using a a form using POST method and PHP but left with placeholders here for the sake of simplicity.
$name = 'name';
$email = 'email';
$phone = 'phone';
$subject = 'subject';
$message = 'message';

// Send Email
// Create the Transport
$transport = (new Swift_SmtpTransport('smtp.office365.com', 587, 'tls'))
    ->setUsername($emailusername)
    ->setPassword($emailpassword);

// Create the Mailer using your created Transport
$mailer = new Swift_Mailer($transport);

function sendVerificationEmail($name, $email, $phone, $subject, $message)
{
    global $mailer;
    $sentfrom = "[email protected]";
    $sentto = "[email protected]";
    $body = 'Message From:' . $name . '<br>' . $email . '<br>' . $phone . '<br>' . $subject . '<br>' . $message;
    // Create a message
    $message = (new Swift_Message("A New Message From " . $name))
        ->setFrom([$sentfrom])
        ->setTo([$sentto])
        ->setBody($body, 'text/html');

    // Send the message
    $result = $mailer->send($message);
}

sendVerificationEmail($name, $email, $phone, $subject, $message);

echo "<script> window.location.assign('./contactformsuccess'); </script>";

编辑:添加日志

[Sun Aug 15 07:34:58.851255 2021] [php:warn] [pid 182629] [client 162.158.167.91:37848] PHP Warning: stream_socket_enable_crypto(): SSL operation failed with code 1. OpenSSL Error messages:\nerror:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed in /var/www/site.com/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/StreamBuffer.php on line 94 [Sun Aug 15 07:34:58.851487 2021] [php:error] [pid 182629] [client 162.158.167.91:37848] PHP Fatal error: Uncaught Swift_TransportException: Unable to connect with TLS encryption in /var/www/site.com/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php:349\nStack trace:\n#0 /var/www/site.com/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php(148): Swift_Transport_EsmtpTransport->doHeloCommand()\n#1 /var/www/site.com/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Mailer.php(65): Swift_Transport_AbstractSmtpTransport->start()\n#2 /var/www/site.com/html/includes/cf2.inc.php(39): Swift_Mailer->send()\n#3 /var/www/site.com/html/includes/cf2.inc.php(42): sendVerificationEmail()\n#4 {main}\n thrown in /var/www/site.com/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/EsmtpTransport.php on line 349

ubuntu smtp digital-ocean
  • 1 个回答
  • 384 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve