2014-10-28 140 views
2

我試圖通過發送5.2.9 PHPMailer的使用產生的SES SDK 2.7以下原料電子郵件sendRawEmail方法:電子郵件編碼與亞馬遜SES sendRawEmail

Date: Tue, 28 Oct 2014 03:34:18 +0000 
From: [email protected] 
Reply-To: [email protected] 
Message-ID: <[email protected]*.dev> 
X-Priority: 3 
X-Mailer: PHPMailer 
MIME-Version: 1.0 
Content-Type: multipart/alternative; 
    boundary="b1_c738074625a476ed8e2793323ad0b3b2" 
Content-Transfer-Encoding: 8bit 
To: [email protected] 
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,只是一個標準「的MessageId」和「請求ID」爲我會成功的發送(和它實際發送)。

我試過了,也沒有附件,但它仍然發送消息作爲亂碼。這是什麼收到: http://prntscr.com/50ij42

我在做什麼錯在這裏?

+0

我一直在試圖通過SES發送帶有附件的電子郵件,嘗試手動創建電子郵件的MIME結構時非常掙扎。明智的想法就是使用PHPMailer爲你創建它。 – Matt 2017-06-21 12:40:06

回答

1

你忘了對數據進行編碼:

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

SDK documentation: ... - 內容必須Base64編碼,如果MIME需要它。

+0

奇怪,我讀「base64編碼(如果需要)」,所以我不認爲這適用於8位編碼。我也認爲它只適用於mime塊本身,而不是整個電子郵件,所以當我的附件是base64編碼自己我雖然這樣做。這雖然解決了問題! – eComEvo 2014-10-31 16:02:21

+0

我同意,措辭有點混亂。 – 2014-10-31 21:48:16