繁体   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