Markus: Korrekter Content-Type für Multipart-Mail mit Inline-Images

Beitrag lesen

Hallo zusammen.

Mittels PHP möchte ich eine Multipart-Mail mit Inline-Images versenden. Leider schaffe ich es momentan nur, daß entweder Googlemail oder Outlook (Version 2007) die Nachricht korrekt darstellen.

Content-Type: multipart/related; boundary=XXXXXXXX
Führt dazu, daß Outlook alles korrekt darstellt, Googlemail das Inline-Image sowie die HTML-Message jedoch als Attachments anzeigt.

Content-Type: multipart/multipart/alternative; boundary=XXXXXXXX
Führt dazu, daß Outlook das Inline-Image sowie die HTML-Message als Attachments anzeigt, Googlemail die Nachricht jedoch korrekt anzeigt.

Andere Webmailer oder Mailclients habe ich noch nicht geprüft, da mir dieses Problem überhaupt erst durch Googlemail aufgeallen ist.

Anbei eine komplette Nachricht inklusive aller Header. Weiß jemand weiter?!

Vorab vielen Dank für Eure Unterstützung!

<?php  
// Boundary / CID  
$boundary = md5(uniqid(rand(), true));  
$cid = md5(uniqid(rand(), true));  
// Header  
$msg .= "From: XXXXXXXX <XXXXXXXX@XXXXXXXX.com>\r\n";  
$msg .= "Reply-To: XXXXXXXX <XXXXXXXX@XXXXXXXX.com>\r\n";  
$msg .= "X-Mailer: PHP5.2.5\r\n";  
$msg .= "X-Sent-By-Ip: XXX.XXX.XXX.XXX\r\n";  
$msg .= "X-Priority: 0\r\n";  
$msg .= "MIME-Version: 1.0\r\n";  
$msg .= "Content-Type: multipart/alternative; boundary=\"" . $boundary . "\"\r\n";  
// Plain  
$msg .= "--" . $boundary . "\r\n";  
$msg .= "Content-Type: text/plain; charset=\"utf-8\"\n";  
$msg .= "Content-Transfer-Encoding: 8bit\r\n";  
$msg .= "Plain Text Mail\n\n";  
// Html  
$msg .= "--" . $boundary . "\n";  
$msg .= "Content-Type: text/html; charset=\"utf-8\"\n";  
$msg .= "Content-Transfer-Encoding: 8bit\r\n";  
$msg .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n";  
$msg .= "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"de-DE\">\n";  
$msg .= "<head>\n";  
$msg .= "<meta http-equiv=\"pragma\" content=\"no-cache\" />\n";  
$msg .= "<meta http-equiv=\"cache-control\" content=\"no-cache\" />\n";  
$msg .= "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\" />\n";  
$msg .= "<meta http-equiv=\"content-style-type\" content=\"text/css\" />\n";  
$msg .= "<meta http-equiv=\"content-script-type\" content=\"text/javascript\" />\n";  
$msg .= "</head>\n";  
$msg .= "<body>\n";  
$msg .= "  <img src=\"cid:" . $cid . "\" width=\"128\" height=\"64\" alt=\"\" />\n";  
$msg .= "</body>\n";  
$msg .= "</html>\n\n";  
// Image  
$msg .= "--" . $boundary . "\n";  
$msg .= "Content-Type: application/octetstream; name=" . $cid . "\n";  
$msg .= "Content-Transfer-Encoding: base64\n";  
$msg .= "Content-ID: <" . $cid . ">\n";  
$msg .= "Content-Disposition:inline; filename=" . $cid . "\n\n";  
$msg .= chunk_split(base64_encode(file_get_contents('XXXXXXXX'))) . "\n\n";  
$msg .= "--" . $boundary . "--\n";  
?>

Beste Grüße,
Markus