assets/s2diemail.php /// Art: Business Logic /// Inhalt: Klasse Email /// Beschreibung: Message Zentrum zum Versenden von Emails /// Benötigt: config.php, db.php /// CCML-Parsing: nein /// ////////////////////////////////////////////////////////////////////////////////////////// /// /// Letzte Änderungen: /// 21.09.2009 quoted_printable_encode Funktionsname angepasst wegen Core Überschneidung /// 22.09.2009 split -> explode /// 27.03.2010 Erweiterung um PDF Versand /// 31.07.2010 HTML Header für Plain Mails angepasst /// ////////////////////////////////////////////////////////////////////////////////////////// ///<07.08.2010/7.0.1.9/> if (!defined('SHOP_TO_DATE')) die('Forbidden'); // HTML Kopf- und Fussdaten für Email define('HTML_MAIL_HEADER', ' '); define('HTML_MAIL_FOOTER', ' '); // Klasse email class email extends db { var $email_id = null; var $client_id = null; var $order_id = null; var $date; var $time; var $to_email; var $to_plain = null; var $from_email; var $from_plain = null; var $subject; var $content_plain; var $content_html = null; var $log; var $pdf = array(); // Konstruktor, öffnet ggf. Datensatz, weist ansonsten für neue Email Datum zu function email($id = null) { $this->db(TABLE_EMAILS); if ($id) { $this->email_id = $id; $this->db_selectobject(array('email_id' => $id)); } else { $this->date = date("Y-m-d"); $this->time = date("H:i:s"); } } // PRIVAT Erzeugt eine Trennkette function create_boundary() { return '-----=' . md5(uniqid(rand())); } // PRIVAT Erzeugt eine Mail mit Bestandteilen Text function create_mime_plain($text) { $myheader = "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\nContent-Transfer-Encoding: 8bit"; $mycontent = $this->wrap_plain($text); return array($myheader, $mycontent); } // PRIVAT Erzeugt eine Mime Mail mit Bestandteilen Text und Html function create_mime_alternative($text, $html) { $boundary = $this->create_boundary(); $myheader = "Content-Type: multipart/alternative;\n\tboundary=\"".$boundary."\""; $mycontent = "\n--".$boundary."\n"; $mycontent .= "Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n"; $mycontent .= "Content-Transfer-Encoding: quoted-printable\n\n"; $mycontent .= $this->my_quoted_printable_encode($this->wrap_plain($text))."\n"; $mycontent .= "\n--".$boundary."\n"; $mycontent .= "Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n"; $mycontent .= "Content-Transfer-Encoding: quoted-printable\n\n"; $mycontent .= $this->my_quoted_printable_encode($html)."\n"; $mycontent .= "\n--".$boundary."--\n"; return array($myheader, $mycontent); } function create_mime_mixed($part, $pdf) { $boundary = $this->create_boundary(); $myheader = "Content-Type: multipart/mixed;\n\tboundary=\"".$boundary."\""; $mycontent = "\n--".$boundary."\n"; $mycontent .= $part; if (isset($pdf['name'])) { $mycontent .= "\n--".$boundary."\n"; $mycontent .= "Content-Type: application/pdf;\n\tname=\"" . $pdf['name'] . "\"\n"; $mycontent .= "Content-Transfer-Encoding: base64\n"; $mycontent .= "Content-Disposition: attachment;\n\tfilename=\"" . $pdf['name'] . "\"\n\n"; $mycontent .= chunk_split(base64_encode(file_get_contents($pdf['filename'])), 76, "\n")."\n"; } $mycontent .= "\n--".$boundary."--\n"; return array($myheader, $mycontent); } // PRIVAT Mail senden function send($html_complete = false) { $this->content_plain = html_entity_decode($this->content_plain); if ($this->content_html && !$html_complete) $this->content_html = HTML_MAIL_HEADER.$this->content_html.HTML_MAIL_FOOTER; // Absender if ($this->from_plain && $this->from_email) $header = 'From: "'.$this->from_plain.'" <'.$this->from_email.'>'."\n"; else if ($this->from_email) $header = 'From: '.$this->from_email."\n"; else $header = ''; $header .= "X-Mailer: shop to date Order-Gateway Version 3.0"; // Kein PDF if (CC_SITE_BILLHASLEFTTHEBUILDING || !isset($this->pdf['name'])) { if (CC_SITE_MAILNOMIME || !$this->content_html) { // Kein HTM oder nur Text list($more_header, $content) = $this->create_mime_plain($this->content_plain); $header .= "\n"; $header .= $more_header; $this->content_html = null; } else { // Alternativ mit HTML und Text list($more_header, $content) = $this->create_mime_alternative($this->content_plain, $this->content_html); $header .= "\nMIME-Version: 1.0\n"; $header .= $more_header; $content = "This is a multi-part message in MIME format.$content"; } // Mit PDF } else { if (CC_SITE_MAILNOMIME || !$this->content_html) { // Kein HTM oder nur Text $part = implode("\n\n", $this->create_mime_plain($this->content_plain)); $this->content_html = null; } else { // Alternativ mit HTML und Text $part = implode("\n\n", $this->create_mime_alternative($this->content_plain, $this->content_html)); } list($more_header, $content) = $this->create_mime_mixed($part, $this->pdf); $header .= "\nMIME-Version: 1.0\n"; $header .= $more_header; $content = "This is a multi-part message in MIME format.\n$content"; } @mail($this->to_email, $this->subject, $content, $header); } // PRIVAT MIME-Encoding function my_quoted_printable_encode($input) { $line_max = 76; $hex = array("0",'1',"2",'3','4',"5",'6','7','8','9','A','B','C','D','E','F'); $lines = explode("\n", $input); $eol = "\n"; $escape = "="; $output = ""; for ($j=0;$j 126) ) { $h2 = floor($dec/16); $h1 = floor($dec%16); $c = $escape.$hex["$h2"].$hex["$h1"]; } if ( (strlen($newline) + strlen($c)) >= $line_max ) { $output .= $newline.$escape.$eol; $newline = ""; } $newline .= $c; } $output .= $newline; if ($jsend($complete); if (CC_SITE_MAILLOG) return $this->db_insertobject(); } // Emails holen function get($fields, $where, $order = null, $page = null, $perpage = null) { return $this->db_get($fields, $where, $order, $page, $perpage); } // Email löschen function delete() { $this->db_delete(array('email_id' => $this->email_id)); } } ?>