【问题标题】:Amazon SES throwing error 500 when I try to send email当我尝试发送电子邮件时,Amazon SES 抛出错误 500
【发布时间】:2021-01-03 18:25:12
【问题描述】:

我已经在我的 ec2 实例上设置了 Amazon SES,就像在这个 link 中一样

当我在我的 ec2 实例的终端上使用命令 php teste.php 时,测试文件工作正常并发送电子邮件,问题是当我尝试发出发布请求以访问此文件并发送电子邮件时,它是抛出错误 500,我不知道如何解决。

这是 chrome 上的错误消息:

关于失眠:

这是我的测试文件:

<?php

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

// location of your Composer autoload.php file.
require '../../../home/ec2-user/vendor/autoload.php';

$sender = 'email@email.com';
$senderName = 'Teste';
$recipient = 'email@email.com';
$usernameSmtp = '[removed for security]';
$passwordSmtp = '[removed for security]';
$host = 'email-smtp.sa-east-1.amazonaws.com';
$port = 587;
$subject = 'Amazon SES test (SMTP interface accessed using PHP)';
$bodyText =  "Email Test\r\nThis email was sent through the
Amazon SES SMTP interface using the PHPMailer class.";

$bodyHtml = '<h1>Email Test</h1>
<p>This email was sent through the
<a href="https://aws.amazon.com/ses">Amazon SES</a> SMTP
interface using the <a href="https://github.com/PHPMailer/PHPMailer">
PHPMailer</a> class.</p>';

$mail = new PHPMailer(true);

try {
  $mail->isSMTP();
  $mail->setFrom($sender, $senderName);
  $mail->Username   = $usernameSmtp;
  $mail->Password   = $passwordSmtp;
  $mail->Host       = $host;
  $mail->Port       = $port;
  $mail->SMTPAuth   = true;
  $mail->SMTPSecure = 'tls';
  $mail->addCustomHeader('X-SES-CONFIGURATION-SET');
  $mail->addAddress($recipient);
  $mail->isHTML(true);
  $mail->Subject    = $subject;
  $mail->Body       = $bodyHtml;
  $mail->AltBody    = $bodyText;
  $mail->Send();
echo "Email sent!", PHP_EOL;
} catch (phpmailerException $e) {
  echo "An error occurred. {$e->errorMessage()}", PHP_EOL;
} catch (Exception $e) {
  echo "Email not sent. {$mail->ErrorInfo}", PHP_EOL;
}

【问题讨论】:

  • 可以分享日志吗?
  • 我不知道在哪里可以找到日志,返回的唯一消息是 500 内部服务器错误,如果我在 Insomnia 上悬停此消息,它会显示:服务器遇到了它没有的情况不知道怎么处理。

标签: amazon-web-services amazon-ec2 amazon-ses


【解决方案1】:

您需要在实例的安全组上打开端口 587 才能使其正常工作。

aws developer form上提出了类似的问题

编辑

使用 SSL

    $mail->Host = 'ssl://email-smtp.sa-east-1.amazonaws.com';
    $mail->SMTPSecure = 'tls';
    $mail->Port = 443;

【讨论】:

  • 你需要分享你得到的错误信息,在前台运行脚本,并在这里分享错误。
  • @ronate 你可以尝试使用 ssl 设置,因为我已经更新了。还有其他几个选项using-phpmailer-and-amazon-ses
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-22
  • 2016-08-22
  • 1970-01-01
相关资源
最近更新 更多