[英]Sending emails from ec2 using SES and SwiftMailer
我已經在California
節點上啟動並運行了我的ec2實例,除了我簡單的contact.php表單之外,其他所有東西都在工作。
我已經讀過很多關於ec2很難發送電子郵件的信息。 而且,似乎沒有任何效果”
因此,我偶然發現了SiftMailer,並使用yum install php-swift-Swift.noarch
將其安裝在運行Amazon 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 ...',數組,在
386行上的/usr/share/pear/Swift/Swift/Transport/AbstractSmtpTransport.php
因此,“ mygmail”是我實際發送的電子郵件,我只是將其輸入。 當我在IAM中創建SES指令要求我創建的憑據時,會得到“ KEY”和“ Secret”。
我也通過SES網絡界面驗證了此電子郵件。
如果需要進一步說明,請告訴我。
不確定是否已解決此問題,但可能是因為您未正確使用憑據,因為您在此處未指定此信息。
我建議嘗試替換:
您的電子郵件地址為'mygmail@gmail.com'
'KEY'
'mygmail@gmail.com'
您的電子郵件地址為'your_gmail_password'
'SECRET'
'your_gmail_password'
這樣的設置對我和Swiftmailer的Yii2都有效。
我認為您需要包括AWS SES的SMTP憑證。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.