【发布时间】: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 网络界面上验证了这封电子邮件。
如果我需要更清楚地说明这一点,请告诉我。
【问题讨论】:
-
@JakeGould 这没什么用
-
你弄明白了吗?
-
多年后 - 不幸的是没有。
标签: php email amazon-ec2 swiftmailer amazon-ses