Aktueller Code:
function sendmail($layout, $from, $to, $subject, $title, $body, $attachedfiles = NULL, $attachedfiles_name = NULL, $cc = "", $bcc = ""){
global $newsletter_layout;
// Text-Mail?
if($newsletter_layout[$layout][2] == "0")
$textmail = true;
else
$textmail = false;
// Layout der Seite laden
if($textmail){
$ausgabe = $body;
}
else{
$ausgabe = implode('', file($newsletter_layout[$layout][2]));
$ausgabe = str_replace('<!--body-->', imap_8bit($body), $ausgabe);
$ausgabe = str_replace('<!--title-->', $title, $ausgabe);
$ausgabe = str_replace('<!--bilder-->', ' ', $ausgabe);
}
// Email zusammensetzen
$eol = PHP_EOL;
$id = md5(uniqid(mt_rand(), true));
$boundary = "----".$id;
$header = "Content-class: urn:content-classes:message".$eol;
$header .= "User-Agent: Free WebMail".$eol;
$header .= "From: ".$from.$eol;
if(!empty($cc))
$header .= "Cc: ".$cc.$eol;
if(!empty($bcc))
$header .= "Bcc: ".$bcc.$eol;
$header .= "X-Priority: 3 (Normal)".$eol;
$header .= "Importance: Normal".$eol;
$header .= "MIME-Version: 1.0".$eol;
if(!empty($attachedfiles))
$header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"".$eol;
else if($textmail)
$header .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
else
$header .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$message = '';
if(!empty($attachedfiles)){
$message .= "--".$boundary.$eol;
if($textmail)
$message .= "Content-Type: text/plain; charset=iso-8859-1".$eol;
else
$message .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$message .= "Content-Transfer-Encoding: quoted-printable".$eol;
$message .= "Content-Disposition: inline".$eol;
}
$message .= $ausgabe.$eol.$eol;
if(!empty($attachedfiles))
$message .= "--".$boundary.$eol;
for($x = 0;$x < count($attachedfiles);$x++){
if(!empty($attachedfiles_name[$x])){
$filename = $attachedfiles_name[$x];
}
else{
$filename = explode('/', $attachedfiles[$x]);
$filename = $filename[count($filename) - 1];
}
$file = fopen($attachedfiles[$x], "r");
$content = fread($file, filesize($attachedfiles[$x]));
fclose($file);
$encodedfile = chunk_split(base64_encode($content));
$message .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Description: ".$attachedfiles[$x].$eol;
$message .= "Content-Disposition: attachment; filename=\"".$filename."\"".$eol.$eol;
$message .= $encodedfile.$eol.$eol."--".$boundary;
}
if(!empty($attachedfiles))
$message.="--";
// Email verschicken
if(mail($to, $subject, $message, $header))
return true;
else
return false;
}