使用Amazon SES sendRawEmail进行电子邮件编码

时间:2014-10-28 05:05:26

标签: php email amazon-web-services aws-sdk

我尝试使用SES SDK 2.7 sendRawEmail方法发送由PHPMailer 5.2.9生成的以下原始电子邮件:

Date: Tue, 28 Oct 2014 03:34:18 +0000
From: someemail@gmail.com
Reply-To: someemail@gmail.com
Message-ID: <c738074625a476ed8e2793323ad0b3b2@*.dev>
X-Priority: 3
X-Mailer: PHPMailer
MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="b1_c738074625a476ed8e2793323ad0b3b2"
Content-Transfer-Encoding: 8bit
To: someperson@gmail.com
Subject: Test subject (TID #1, SID #2)

--b1_c738074625a476ed8e2793323ad0b3b2
Content-Type: text/plain; charset=us-ascii

Test email for _Some One_!


--b1_c738074625a476ed8e2793323ad0b3b2
Content-Type: text/html; charset=us-ascii

Test email for <i>Some One</i>!


--b1_c738074625a476ed8e2793323ad0b3b2--

以下是用于生成原始电子邮件然后发送的代码:

$mail = new PHPMailer();

$mail->addAddress($to);
$mail->setFrom($from);
$mail->Subject = $subject;
$mail->CharSet = $char_set;
$mail->AltBody = $text;
$mail->Body = $html;
$mail->isHTML(true);
$mail->addAttachment($attachment);

$mail->preSend();

$args = [
    'Source'       => $from,
    'Destinations' => [$to],
    'RawMessage'   => [
        'Data' => $mail->getSentMIMEMessage()
    ]
];

$aws = Aws\Common\Aws::factory(app_path() . '/config/aws.php');

$ses = $aws->get('ses');

$send_result = $ses->sendRawEmail($args);

我在$send_result中没有错误,只是标准的&#39; MessageId&#39;和&#39; RequestId&#39;就像我成功发送一样(它确实发送)。

我已尝试使用和不使用附件,但它仍然将消息作为乱码发送。这是收到的: http://prntscr.com/50ij42

我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

您忘了编码数据:

'RawMessage'   => [
    'Data' => base64_encode( $mail->getSentMIMEMessage() )
]

来自SDK documentation:   ...    - 如果MIME需要,内容必须是base64编码的。