簡體   English   中英

使用PHP SDK從Amazon SES發送HTML郵件

[英]Sending HTML Mails from Amazon SES using PHP SDK

我正在開發一項從AWS SES服務發送電子郵件的服務。 我已經能夠發送純文本郵件,但我需要在其中一個案例中發送豐富的HTML郵件。 這是我使用的代碼:

header("MIME-Version: 1.0; Content-type: text/html; charset=iso-8859-1");

    require_once(dirname(__FILE__).'/AWSSDKforPHP/sdk.class.php');

// Instantiate the Amazon class
$ses = new AmazonSES();


$source = 'abc@www..com';

$dest = array('ToAddresses'=>array($to));

$message = CFComplexType::map(array('Subject.Data'=>$subject, 'Body.Html.Data'=>$message_mail));

$rSendEmail = $ses->send_email($source, $dest, $message);

message_mail是放在表格中的一些HTML文本。 我已經嘗試了send_email和send_raw_email,但它們都沒有用。 我需要做一些額外的或不同的事嗎?

我知道這是一個古老的問題,但仍在寫一個答案。 並希望它將來會幫助某人。

$m = new SimpleEmailServiceMessage();
$m->addTo('receiver email address');
$m->setFrom('send email address');
$m->setSubject('testing!');

$body= '<b>Hello world</b>';
$plainTextBody = '';

$m->setMessageFromString($plainTextBody,$body);    
print_r($ses->sendEmail($m));

這對我有用(不使用sdk或smtp):

require_once('ses.php');

$ses = new SimpleEmailService('accessKey', 'secretKey');

$m = new SimpleEmailServiceMessage();
$m->addTo('addressee@example.com');
$m->setFrom('Name <yourmail@example.com>');
$m->setSubject('You have got Email!');
$m->setMessageFromString('Your message');
$ses->sendEmail($m);

你可以從http://www.orderingdisorder.com/aws/ses/獲得ses.php

我嘗試使用SES SDK,並不容易使用。 我最終使用PHPMailer通過SMTP連接到SES。 首先,從Amazon SES中設置SMTP訪問,然后將這些行添加到PHPMailer以使其通過TLS連接到SES:

$mail = new PHPMailer();

$mail->IsSMTP(true);
$mail->SMTPAuth = true;
$mail->Mailer = "smtp";
$mail->Host= "tls://email-smtp.us-east-1.amazonaws.com";
$mail->Port = 465;
$mail->Username = "";  // SMTP username (Amazon Access Key)
$mail->Password = "";  // SMTP Password (Amazon Secret Key)

// ... the rest of PHPMailer code here ...

PHPMailer非常擅長豐富的電子郵件(帶有文本回退),嵌入式圖像和附件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM