HTML E-Mail per PHP mit mehreren Bildern versenden

?php

Grünschnabel
Hallo an alle im Forum!

Ich habe bereits lange im Internet nach dem Fehler gesucht und keine Lösung gefunden.

Und zwar habe ich folgendes Problem:
Ich möchte morgen eine sehr wichtige HTML-Mail versenden mit mehreren Grafiken im Anhang (intern verlinkt).

Mit einem Bild funktionierts einwandfrei! Hänge ich jedoch mehrere Bilder in den Anhang funktioniert es nicht mehr! (Es wird nur das erste Bild angezeigt (center_bg.png), das zweite jedoch wird einfach weggelassen)

Hier ist der PHP-Code:
PHP:
<?php

  $ImageLocation ="center_bg.png";
  $ImgName = "center_bg.png";
  $ImageLocation1 ="footer.png";
  $ImgName1 = "footer.png";
  $MailFrom="Name";
  $MailFromAdr="test@example.com";
  $MailTo ="inf@test.de";
  $MailToSubject = "Test";

  $CID = md5(uniqid (rand(), 1));

  $mime_boundary = "" . md5(uniqid(mt_rand(), 1));
 $mime_boundary1 = "" . md5(uniqid(mt_rand(), 2));


  $Header= "From:$MailFrom<$MailFromAdr>\n";
  $Header.= "X-Mailer: PHP/" . phpversion(). "\n";  
  $Header.= "MIME-Version: 1.0\n";
  $Header.= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"; type=\"text/plain\"\n"; 

  $Header.= "Your Mail-Client is not MIME ready!";

  $MailBody = "--".$mime_boundary."\n";
  $MailBody.= "Content-Type: Text/HTML; charset=iso-8859-1$EOL";  
  $MailBody.= "Content-Transfer-Encoding: quoted-printable\n\n";  
  $MailBody.= '

<html>
<head>
  <title>Titel</title>
  <style type="text/css">

    @font-face {
	font-family: Myraid Pro;}

    html, body { 
	height: 100%;
	color: #006ea7;
	font-size:16px;
     	font-family: Myraid Pro;}

    #top {
	position: absolute;
	top: 37px;
	left: 50%;
	margin-left: -274px;
	width: 548px;
	height: 151px;
	z-index: 0; }

    #content {
	position: absolute;
	height: 403px;
	width: 500px;
	left: 50%;
	margin-left: -250px;
	top: 188px;
	z-index: 4; }

    #content_bg {
	position: absolute;
	height: 403px;
	width: 548px;
	left: 50%;
	margin-left: -274px;
	top: 188px;
	z-index: 4; }

    #push {
	height: 0px; }

    #footer {
	position: absolute;
	width: 548px;
	height: 137px;
	left: 50%;
	margin-left: -274px;
	margin-bottom: 20px;
	margin-top: 0px;
	top: 591px;
	z-index: 5; }

  </style>
</head>
<body background="http://www.test.de/bg.jpg">
  <div id="top"><img src="http://www.test.de/top.png"></div>
  <div id="content_bg"><img src="';

  $MailBody.= "cid:" . $CID . "." . $ImgName;

  $MailBody.= '"></div>
  <div id="content">
	asjbkasdjaskjb
  </div>
  <div id="footer"><img src="';


  $MailBody.= "cid:" . $CID . "." . $ImgName1;

  $MailBody.= '"></div>
</body>
</html>

';
  $MailBody.= "\n\n";
  $MailBody.= "--".$mime_boundary."\n";  


  $fp = fopen ($ImageLocation, "rb");
  $str = fread ($fp, filesize ($ImageLocation));
  $data = chunk_split(base64_encode($str));
  $content.= "Content-Type: image/png\n";
  $content.= "Content-ID: <$CID.$ImgName>\n";
  $content.= "Content-Transfer-Encoding: base64\n";
  $content.= "Content-Disposition: inline; filename=\"$ImgName\"\n\n";
  fclose($fp);


  $content.= $data;
  $MailBody.= $content;
  $MailBody.= "--".$mime_boundary."--\n";  

//-------------------------------------------

  $MailBody.= "\n\n";
  $MailBody.= "--".$mime_boundary."\n";  


  $fp = fopen ($ImageLocation1, "rb");
  $str = fread ($fp, filesize ($ImageLocation1));
  $data = chunk_split(base64_encode($str));
  $content.= "Content-Type: image/png\n";
  $content.= "Content-ID: <$CID.$ImgName1>\n";
  $content.= "Content-Transfer-Encoding: base64\n";
  $content.= "Content-Disposition: inline; filename=\"$ImgName1\"\n\n";
  fclose($fp);


  $content.= $data;
  $MailBody.= $content;
  $MailBody.= "--".$mime_boundary."--\n";  

   mail($MailTo, $MailToSubject, $MailBody, $Header); 

?>
Ich vermute, dass es sich um ein MIME-Fehler (--$mime_boundary--) handelt, habe ihn jedoch nicht gefunden!

Ich hoffe ihr könnt mir helfen und danke bereits im Voraus,

?php
 
Zuletzt bearbeitet:
Vielen Dank für den Tipp!
Wenn es mit dieser Variante nicht funktioniert, werde ich es so probieren!
 
Zurück