3 require_once('include/email.php');
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
16 * @param additionalMailHeader additions to the smtp mail header
18 static public function send($params) {
20 $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
21 $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'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 $params['additionalMailHeader'] .
32 "From: $fromName <{$params['fromEmail']}>\n" .
33 "Reply-To: $fromName <{$params['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($params['textVersion']));
39 $htmlBody = chunk_split(base64_encode($params['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 $params['toEmail'], // send to address
54 $messageSubject, // subject
55 $multipartMessageBody, // message body
56 $messageHeader // message headers
58 logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
59 logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);