2 class EmailNotification {
4 * Send a multipart/alternative message with Text and HTML versions
6 * @param fromName name of the sender
7 * @param fromEmail email fo the sender
8 * @param replyTo replyTo address to direct responses
9 * @param toEmail destination email address
10 * @param messageSubject subject of the message
11 * @param htmlVersion html version of the message
12 * @param textVersion text only version of the message
14 static public function sendTextHtmlEmail($fromName,$fromEmail,$replyTo,$toEmail,$messageSubject,$htmlVersion,$textVersion) {
15 logger("sendTextHtmlEmail: BEGIN");
16 logger("fromName: " . $fromName);
17 logger("fromEmail: " . $fromEmail);
18 logger("replyTo: " . $replyTo);
19 logger("toEmail: " . $toEmail);
20 logger("messageSubject: " . $messageSubject);
21 //logger("htmlVersion: " . $htmlVersion);
22 //logger("textVersion: " . $textVersion);
24 // generate a mime boundary
25 $mimeBoundary =rand(0,9)."-"
26 .rand(10000000000,9999999999)."-"
27 .rand(10000000000,9999999999)."=:"
30 // generate a multipart/alternative message header
32 "From: {$fromName} <{$fromEmail}>\n" .
33 "Reply-To: {$replyTo}\n" .
34 "MIME-Version: 1.0\n" .
35 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
37 // assemble the final multipart message body with the text and html types included
38 $textBody = chunk_split(base64_encode($textVersion));
39 $htmlBody = chunk_split(base64_encode($htmlVersion));
40 $multipartMessageBody =
41 "--" . $mimeBoundary . "\n" . // plain text section
42 "Content-Type: text/plain; charset=UTF-8\n" .
43 "Content-Transfer-Encoding: base64\n\n" .
45 "--" . $mimeBoundary . "\n" . // text/html section
46 "Content-Type: text/html; charset=UTF-8\n" .
47 "Content-Transfer-Encoding: base64\n\n" .
49 "--" . $mimeBoundary . "--\n"; // message ending
53 $toEmail, // send to address
54 $messageSubject, // subject
55 $multipartMessageBody, // message body
56 $messageHeader // message headers
58 logger("sendTextHtmlEmail: END");