使用PHPMailer和Amazon SES

Ans*_*imu 10 php email amazon-web-services amazon-ses

我正在使用Amazon SES.我正在尝试使用PHPMailer从我的PHP脚本发送电子邮件.

我已经验证了两个电子邮件ID,并尝试向此邮件ID发送邮件.但它会引发以下错误.

错误

SERVER -> CLIENT: 220 email-smtp.amazonaws.com ESMTP SimpleEmailService-693939519  QEPGeLndQQq5vJ53VMXU
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-email-smtp.amazonaws.com250-8BITMIME250-SIZE 10485760250- STARTTLS250-AUTH PLAIN LOGIN250 Ok
CLIENT -> SERVER: STARTTLS
SERVER -> CLIENT: 220 Ready to start TLS
CLIENT -> SERVER: EHLO localhost
SERVER -> CLIENT: 250-email-smtp.amazonaws.com250-8BITMIME250-SIZE 10485760250-STARTTLS250-AUTH PLAIN LOGIN250 Ok
CLIENT -> SERVER: AUTH LOGIN


SMTP NOTICE: EOF caught while checking if connected
SMTP connect() failed.
Mailer Error: SMTP connect() failed.
Run Code Online (Sandbox Code Playgroud)

以下是我的PHP脚本:

<?php

//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 'phpmailer/PHPMailerAutoload.php';

//Create a new PHPMailer instance
$mail = new PHPMailer();

//Tell PHPMailer to use SMTP
$mail->isSMTP();

//Enable SMTP debugging

$mail->SMTPDebug = 2;

//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';

//Set the hostname of the mail server
$mail->Host = 'email-smtp.us-east-1.amazonaws.com';

//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission
// I tried PORT 25, 465 too
$mail->Port = 587;

//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';

//Whether to use SMTP authentication
$mail->SMTPAuth = true;

//Username to use for SMTP authentication - use full email address for gmail
$mail->Username = "SES Secret ID";

//Password to use for SMTP authentication
$mail->Password = "SES Secret Key";

//Set who the message is to be sent from
$mail->setFrom('sender@example.com', 'sender');

//Set who the message is to be sent to
$mail->addAddress('receiver@example.com', 'receiver');

//Set the subject line
$mail->Subject = 'PHPMailer GMail SMTP test';


$mail->Body = 'This is a plain-text message body';
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';

//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>
Run Code Online (Sandbox Code Playgroud)

我尝试了很多通过互联网找到的解决方案,特别是stackoverflow.

什么都行不通!!

Vic*_*mes 10

我设法让它发挥作用.

$ mail-> Port = 587; 

// Username to use for SMTP authentication - use full email address for gmail 
$ mail-> Username = "Amazon SES Secret ID"; 

// Password to use for SMTP authentication 
$ mail-> Password = "Amazon SES Secret Key"; 
Run Code Online (Sandbox Code Playgroud)

要创建凭据,请访问以下链接:https://console.aws.amazon.com/ses/home?region = us-east-1#smtp-setting:

要发送电子邮件,发送电子邮件,因为您收到的电子邮件必须由亚马逊注册和检查.(https://console.aws.amazon.com/ses/home?region=us-east-1#verified-senders-mail :)

你可以找到我的任何问题.我希望我帮忙


leo*_*eon 8

我有同样的问题,当我改变主机名以ssl://开头时,我只能让它工作.这样可行:

$mail = new PHPMailer;
Run Code Online (Sandbox Code Playgroud)

$ mail-> SMTPDebug = 3; //启用详细调试输出

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'ssl://email-smtp.us-west-2.amazonaws.com';  // Specify main and backup SMTP servers

$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'blah';                 // SMTP username
$mail->Password = 'blahblah';                           // SMTP password


$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 443;                  
Run Code Online (Sandbox Code Playgroud)