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) {
16 // generate a mime boundary
17 $mimeBoundary =rand(0,9)."-"
18 .rand(10000000000,9999999999)."-"
19 .rand(10000000000,9999999999)."=:"
22 // generate a multipart/alternative message header
24 "From: {$fromName} <{$fromEmail}>\n" .
25 "Reply-To: {$replyTo}\n" .
26 "MIME-Version: 1.0\n" .
27 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
29 // assemble the final multipart message body with the text and html types included
30 $textBody = chunk_split(base64_encode($textVersion));
31 $htmlBody = chunk_split(base64_encode($htmlVersion));
32 $multipartMessageBody =
33 "--" . $mimeBoundary . "\n" . // plain text section
34 "Content-Type: text/plain; charset=UTF-8\n" .
35 "Content-Transfer-Encoding: base64\n\n" .
37 "--" . $mimeBoundary . "\n" . // text/html section
38 "Content-Type: text/html; charset=UTF-8\n" .
39 "Content-Transfer-Encoding: base64\n\n" .
41 "--" . $mimeBoundary . "--\n"; // message ending
45 $toEmail, // send to address
46 $messageSubject, // subject
47 $multipartMessageBody, // message body
48 $messageHeader // message headers
50 logger("sendTextHtmlEmail: END");