【问题标题】:Sending emails from ec2 using SES and SwiftMailer使用 SES 和 SwiftMailer 从 ec2 发送电子邮件
【发布时间】:2014-06-20 21:34:18
【问题描述】:

我已经在 California 节点上启动并运行我的 ec2 实例,除了我的简单的 contact.php 表单之外,一切都在工作。

我读过很多关于 ec2 很难发送电子邮件的信息。而且,似乎没有任何效果”

因此,我偶然发现了 SiftMailer,并使用 yum install php-swift-Swift.noarch 将其安装在运行亚马逊 linux 的 ec2 实例上

我还在俄勒冈集群上设置了 ses 凭据(因为他们在加州集群上没有邮件程序)

现在代码非常简单:

<?php
    require '/usr/share/pear/Swift/swift_required.php';
    $transport = new Swift_SmtpTransport(
      'email-smtp.us-west-2.amazonaws.com', 465, 'ssl', 'KEY' ,'SECRET'  );
 // $transport->setUserName('')


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

  //Create the message
 $message = Swift_Message::newInstance();
 $message->setSubject("What up?");
 $message->setFrom(array('mygmail@gmail.com'));
 $message->setTo(array('mygmail@gmail.com'));
 $message->setBody("
     <p>
     Dude, I'm <b>totally</b> sending you email via AWS.
     </p>
     ", 'text/html');

$mailer->send( $message );

 ?>

现在我得到的错误是

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Expected response 
code 250 but got code "530", with message "530 Authentication required "' in 
/usr/share/pear/Swift/Swift/Transport/AbstractSmtpTransport.php:386 Stack trace: #0 
/usr/share/pear/Swift/Swift/Transport/AbstractSmtpTransport.php(281): 
Swift_Transport_AbstractSmtpTransport->_assertResponseCode('530 Authenticat...', Array) #1 
/usr/share/pear/Swift/Swift/Transport/EsmtpTransport.php(245): 
Swift_Transport_AbstractSmtpTransport->executeCommand('MAIL FROM: executeCommand('MAIL 
FROM: _doMailFromCommand('mygmail@gmail...') #4 
/usr/share/pear/Swift/Swift/Transport/AbstractSmtpTransport.php(444): 
Swift_Transport_AbstractSmtpTransport->_doMailTransaction(Object(Swift_Message), 

'mygmail@gmail...',数组,在
/usr/share/pear/Swift/Swift/Transport/AbstractSmtpTransport.php 在第 386 行

所以“mygmail”是我的实际电子邮件,我只是将其放入我的帖子中。 'KEY' 和 'Secret' 是我在 IAM 中创建 SES 说明告诉我要制作的凭证时得到的。

我也在 SES 网络界面上验证了这封电子邮件。

如果我需要更清楚地说明这一点,请告诉我。

【问题讨论】:

标签: php email amazon-ec2 swiftmailer amazon-ses


【解决方案1】:

不确定您是否解决了这个问题,但可能是您错误地使用了您的凭据,因为您没有在此处指定此信息。

我建议尝试将:
'KEY' 替换为您的电子邮件地址 'mygmail@gmail.com'
'SECRET' 替换为您的电子邮件地址 'your_gmail_password'

这样的设置在 Yii2 和 Swiftmailer 上对我有用。

【讨论】:

    【解决方案2】:

    我认为您需要包含 AWS SES 的 SMTP 凭证。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-12
      • 2012-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多