简体   繁体   English

使用SES和SwiftMailer从ec2发送电子邮件

[英]Sending emails from ec2 using SES and SwiftMailer

I have up and running my ec2 instance on a California node Everything is working except my simple contact.php form. 我已经在California节点上启动并运行了我的ec2实例,除了我简单的contact.php表单之外,其他所有东西都在工作。

I have read alot about ec2 being really hard to send emails from. 我已经读过很多关于ec2很难发送电子邮件的信息。 And it is, nothing seems to be working" 而且,似乎没有任何效果”

I have thus stumbled upon SiftMailer and installed it on the ec2 instance running Amazon's linux using yum install php-swift-Swift.noarch 因此,我偶然发现了SiftMailer,并使用yum install php-swift-Swift.noarch将其安装在运行Amazon linux的ec2实例上

I have also set up the ses credentials on the Oregon cluster (because they don't have a mailer on the California one) 我还在俄勒冈州群集上设置了ses凭据(因为它们在加利福尼亚州没有邮件发件人)

Now for the code Very Simple: 现在获取非常简单的代码:

<?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 );

 ?>

Now the error that I get is 现在我得到的错误是

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...', Array, in 'mygmail @ gmail ...',数组,在
/usr/share/pear/Swift/Swift/Transport/AbstractSmtpTransport.php on line 386 386行上的/usr/share/pear/Swift/Swift/Transport/AbstractSmtpTransport.php

So 'mygmail' is my actual email i just put that in for my post. 因此,“ mygmail”是我实际发送的电子邮件,我只是将其输入。 And the 'KEY' and 'Secret' are the ones I got when I created the credentials in IAM that the SES instructions told me to make. 当我在IAM中创建SES指令要求我创建的凭据时,会得到“ KEY”和“ Secret”。

ALSO I verified this email on SES web interface as well. 我也通过SES网络界面验证了此电子邮件。

Please let me know if I need to make this more clear. 如果需要进一步说明,请告诉我。

Not sure if you fixed this or not, but it might be that you incorrectly used your credentials, as you haven't specified this info here. 不确定是否已解决此问题,但可能是因为您未正确使用凭据,因为您在此处未指定此信息。

I would suggest to try to replace: 我建议尝试替换:
'KEY' with your email address 'mygmail@gmail.com' 您的电子邮件地址为'mygmail@gmail.com' 'KEY' 'mygmail@gmail.com'
'SECRET' with your email address 'your_gmail_password' 您的电子邮件地址为'your_gmail_password' 'SECRET' 'your_gmail_password'

Such settings worked for me on Yii2 with Swiftmailer. 这样的设置对我和Swiftmailer的Yii2都有效。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM