i went with a mime-mail to solve that. i dont know if its the best way, but it works. here my script to send a mime mail with attached pdfs:
# split emailadress
if ($kunden->actKunde[0]['KNDK_EMAIL'] != "") {
$emails = explode(";", $kunden->actKunde[0]['KNDK_EMAIL']);
if(count($emails)<1) {
print("No email adress specified.<br />");
exit();
}
}
else {
print("No adress specified.<br />");
exit();
}
# use first adress
$to = $emails[0];
# sender
$from = "me@mydomain.com";
# sender name
$fromName = "crosbystillsnash";
# reply-adress
$answerTo = "replyto@mydomain.com";
# subject
$subject = $_POST['emailSubject2'];
# path to pdfs that are attached
$angebotsdir = "here/my/pdf/that/i/want/to/attach/are/saved/";
# attachments are posted from another script (which attachments from $angebotsdir are to be attached)
$attach = $_POST['sendData'];
# not important
$angeboteOfPerson = $angebot->getAngeboteOfPerson ($_GET['actKunde']);
# boundaries of multipart-mail
$boundary1 = "----=_NextPart0001";
$boundary2 = "----=_NextPart0002";
# --------------------------------
# ---------------------------------
# Start MIME 1.0 Mail
$header = "MIME-Version: 1.0\n";
$header.= "From: ".$fromName." <$from>\n";
$header.= "Return-Path: <$answerTo>\n";
$header.= "Content-type: multipart/mixed; boundary=\"".$boundary1."\"\n\n";
$header.= "This is a multipart message in MIME format\n\n";
$header.= "--$boundary1\n";
$header.= "Content-Type: multipart/alternative; boundary=\"".$boundary2."\"\n\n";
# ---------------------------- text/plain
# Start part: text/plain
$header.= "--$boundary2\n";
$header.= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$header.= "Content-Transfer-Encoding: quoted-printable\n\n";
# Email text text/plain (posted from prev script)
$mailText1 = strip_tags($_POST['emailText']);
$mailText1 = str_replace("\\", "", $mailText1);
$header.= $mailText1."\n";
$header.= "\n\n";
# write contents of pdfs in text/plain (contents are saved in db)
if (count($attach)>0) {
$header.= "There are ".count($attach)." files attached.\n";
for ($i=0; $i<count($attach); $i++) {
# get contents of each pdf text/plain
$attachm = $angebot->getAngebotdaten($attach[$i]);
$header.= $attachm[0]['ANGDA_NUMMER']."\n";
$header.= $attachm[0]['ANGDA_TITEL']."\n";
$header.= str_pad("Nettosumme: ", 20, "_", STR_PAD_RIGHT);
$header.= str_pad(" Euro ".number_format($attachm[0]['ANGDA_NETTOSUMME'], 2), 10, "_", STR_PAD_LEFT)."\n";
$header.= str_pad("MwSt: ", 20, "_", STR_PAD_RIGHT);
$header.= str_pad(" Euro ".number_format($attachm[0]['ANGDA_MEHRWERTSTEUER'], 2), 10, "_", STR_PAD_LEFT)."\n";
$header.= str_pad("Bruttosumme: ", 20, "_", STR_PAD_RIGHT);
$header.= str_pad(" Euro ".number_format($attachm[0]['ANGDA_BRUTTOSUMME'], 2), 10, "_", STR_PAD_LEFT)."\n\n";
}
}
# clients number text/plain
$header.= "Ihre Kundennummer:".$_GET['actKunde']."\n";
$header.= "\n\n\n";
# Mail Ende text/plain
$header.= "last text in email.\n\n";
$header.= "\n\n";
# Absender text/plain
$header.= "your name\n";
# End text/plain-part
$header.= "--$boundary2\n";
# -------------------------------- text/html
# Start part: text/html
$header.= "Content-Type: text/html; charset=\"iso-8859-1\"\n";
$header.= "Content-Transfer-Encoding: quoted-printable\n\n";
# Start html code text/html
$header.= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">\n";
$header.= "<HTML>\n";
$header.= "<HEAD>\n";
$header.= "<TITLE>[url]www.cd-logodruck.de[/url]</TITLE>";
# Styles text/html
$header.= "<STYLE>\n";
$header.= "BODY {font-family: verdana; font-size: 11px; background-color: #ffcc33;}\n";
$header.= "H1 {font-family: verdana; font-size: 16px; color: #ffffff; background-color: transparent; font-weight: bold;}\n";
$header.= "table {font-family: verdana; font-size: 11px; background-color: #ffffff;}\n";
$header.= "td {font-family: verdana; font-size: 11px; background-color: #ffcc33;}\n";
$header.= "td.puffer {font-family: verdana; font-size: 11px; background-color: #ffffff;}\n";
$header.= "</STYLE>\n";
$header.= "</HEAD>\n";
$header.= "<BODY>\n";
$header.= "<H1>cd-logodruck.de</H1>\n";
# Email text text/html
$mailText = str_replace("\n", "<br />", $_POST['emailText']);
$mailText = str_replace("\\", "", $mailText);
$header.= $mailText."<br />\n<br />\n";
# client's number text/html
$header.= "Ihre Kundennummer: ".$_GET['actKunde']."<br />\n";
# preview of each attachments text/html
if (count($attach)>0) {
$header.= "<table width=100%>\n";
for ($i=0; $i<count($attach); $i++) {
# get contents of pdf from db
$attachment = $angebot->getAngebotdaten($attach[$i]);
$header.= "<tr>\n";
$header.= "<td width=10%>\n";
$header.= $attachment[0]['ANGDA_NUMMER']." ";
$header.= "<br />(".$attachment[0]['ANGDA_PRODUKTION'].")";
$header.= "</td>\n";
$header.= "<td width=40%><b>";
$header.= $attachment[0]['ANGDA_TITEL']."</b></td>\n";
$header.= "<td align=right width=30% align=right>";
$header.= "Netto: € ".number_format($attachment[0]['ANGDA_NETTOSUMME'], 2)."<br />";
$header.= "<b>Brutto: € ".number_format($attachment[0]['ANGDA_BRUTTOSUMME'], 2)."</b>";
$header.= "</td>\n";
$header.= "</tr>\n";
}
$header.= "</table>\n";
}
# End email text/html
$header.= "<br />finishing text.<br />";
$header.= "<br /><br />";
# Absender text/html
$header.= "...sincerely..... your name<br />\n";
$header.= "</BODY>\n";
$header.= "</HTML>\n";
# End text-parts
$header.= "--$boundary2--\n\n";
# --------------------------- attachments pdf
# attachments
for ($i=0; $i<count($attach); $i++) {
# add new part to email for each attachment
$header.= "--$boundary1\n";
# open attachment
$file[$i] = fopen($angebotsdir.$attach[$i].".pdf", 'rb');
# read attachment
$data[$i] = fread($file[$i], filesize($angebotsdir.$attach[$i].".pdf"));
fclose($file[$i]);
# encode attachment base64
$header.= "Content-Transfer-Encoding: base64\n";
$header.= "Content-Disposition: attachment; filename=\"".$attach[$i].".pdf\"\n\n";
$header.= chunk_split(base64_encode($data[$i]));
}
# end MIME-mail header
$header.= "--$boundary1--\n\n";
# -----------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------
# send email
if (mail($to, $subject, $message, $header)) {
print("Email was sent to '$to'.<br />\n");
# mark offers as sent in db
for ($i=0; $i<count($attach); $i++) {
$angebot->markAngebotSent($attach[$i]);
}
}