3 require_once('include/email.php');
5 class EmailNotification {
7 * Send a multipart/alternative message with Text and HTML versions
9 * @param fromName name of the sender
10 * @param fromEmail email fo the sender
11 * @param replyTo replyTo address to direct responses
12 * @param toEmail destination email address
13 * @param messageSubject subject of the message
14 * @param htmlVersion html version of the message
15 * @param textVersion text only version of the message
17 static public function sendTextHtmlEmail($fromName,$fromEmail,$replyTo,$toEmail,$messageSubject,$htmlVersion,$textVersion) {
19 $fromName = email_header_encode($fromName,'UTF-8');
20 $messageSubject = email_header_encode($messageSubject,'UTF-8');
23 // generate a mime boundary
24 $mimeBoundary =rand(0,9)."-"
25 .rand(10000000000,9999999999)."-"
26 .rand(10000000000,9999999999)."=:"
29 // generate a multipart/alternative message header
31 "From: {$fromName} <{$fromEmail}>\n" .
32 "Reply-To: {$replyTo}\n" .
33 "MIME-Version: 1.0\n" .
34 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
36 // assemble the final multipart message body with the text and html types included
37 $textBody = chunk_split(base64_encode($textVersion));
38 $htmlBody = chunk_split(base64_encode($htmlVersion));
39 $multipartMessageBody =
40 "--" . $mimeBoundary . "\n" . // plain text section
41 "Content-Type: text/plain; charset=UTF-8\n" .
42 "Content-Transfer-Encoding: base64\n\n" .
44 "--" . $mimeBoundary . "\n" . // text/html section
45 "Content-Type: text/html; charset=UTF-8\n" .
46 "Content-Transfer-Encoding: base64\n\n" .
48 "--" . $mimeBoundary . "--\n"; // message ending
52 $toEmail, // send to address
53 $messageSubject, // subject
54 $multipartMessageBody, // message body
55 $messageHeader // message headers
57 logger("sendTextHtmlEmail: END");