我有一个ec2服务器订阅,我正在尝试使用SES使用PHPMailer发送电子邮件。出于某种原因,Mails不是从SES服务器发送的。邮件来自其他服务器。我与AWS支持成员交谈,他确认我所拥有的所有代码都是正确的,他无法提供任何有关我的PHP代码的帮助。
他的回复是
Thank you for your time speaking today.
As discussed, your a PHP Mailer is not relaying on SES, despite your configuration seems to be correct, it's not triggering SES SMTP Servers.
The line below shows that your message was sent from the EC2 directly, without pass through SES.
Received: from ip-xxxxx.ap-southeast-1.compute.internal (ec2-yyyyyy.ap-southeast-1.compute.amazonaws.com. [yyyyyyy])
我的示例PHPMailer代码是
<?php
require 'vendor/phpmailer/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 3; // Enable verbose debug output
//$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'email-smtp.us-east-1.amazonaws.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'smtp-username'; // SMTP username
$mail->Password = 'smtp-password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
$mail->setFrom('contact@example.com', 'John Doer');
$mail->addAddress('abc@gmail.com', 'Random'); // Add a recipient
$mail->addAddress('xyz@gmail.com'); // Name is optional
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
感谢任何帮助。