2013-10-21 61 views
0

每當我嘗試嵌入圖片時,GMail將顯示一個空白內容而不是HTML郵件。PHPMailer和AddEmbeddedImage導致空郵件內容

下面是代碼:

$body = file_get_contents($filesDir . '/emails/wbd.html'); 
$mail = new \PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPDebug = 1; 
$mail->SMTPAuth = $c['config']['mail.params']['auth']; 
$mail->SMTPSecure = $c['config']['mail.params']['secure']; 
$mail->Host = $c['config']['mail.params']['host']; 
$mail->Port = $c['config']['mail.params']['port']; 
$mail->Username = $c['config']['mail.params']['user']; 
$mail->Password = $c['config']['mail.params']['password']; 
$mail->IsHTML(true); 
$mail->SetFrom('[email protected]', 'Some name'); 
$mail->Subject = 'Some subject'; 
$mail->Body = $body; 
$mail->AddEmbeddedImage($filesDir . '/emails/img/community-i.png', 'community-i', 'community-i.png'); 
$mail->AddAddress($to); 
$mail->Send(); 

如果我刪除函數調用AddEmbeddedImage,然後將HTML郵件發送。 圖片的路徑$ filesDir。 '/emails/img/community-i.png'是正確的功能AddEmbeddedImage返回true(並且不正確的路徑將顯示HTML消息)。

我也嘗試只是這一點:

$mail->AddEmbeddedImage($filesDir . '/emails/img/community-i.png', 'community-i'); 
$mail->Body = 'Embedded Image: <img alt="PHPMailer" src="cid:community-i"> Here is an image!'; 

但同樣的問題,空白內容(如果我評論AddEmbeddedImage函數調用,內容將顯示出來,並如預期,而不是形象,ALT標籤出現)。

我在Gmail,Yahoo和Hotmail上測試過,並且對所有地址都有同樣的問題。

+0

另一個地址電子郵件地址會發生什麼情況?電子郵件內容中使用的圖像? – 2013-10-21 23:11:17

+0

你是什麼意思「地址電子郵件地址」? – Matthew

+0

對不起,請將其發送到非Gmail地址。 – 2013-10-21 23:15:08

回答

0

確保您的PHPMailer庫是最新的!