4

我正在开发一项从 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 但它们都没有工作。我需要做一些额外的或不同的事情吗?

4

3 回答 3

4

我知道这是个老问题,但仍在写一个答案。并希望它将来对某人有所帮助。

$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));
于 2013-09-21T06:31:28.803 回答
3

这对我有用(不使用 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

于 2013-07-10T04:10:54.423 回答
2

我尝试使用 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 非常擅长丰富的电子邮件(带有文本回退)、嵌入的图像和附件。

于 2013-05-17T16:54:08.277 回答