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 call_hooks('emailer_send_prepare', $params);
22 $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
23 $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
25 // generate a mime boundary
26 $mimeBoundary =rand(0,9)."-"
27 .rand(10000000000,9999999999)."-"
28 .rand(10000000000,9999999999)."=:"
31 // generate a multipart/alternative message header
33 $params['additionalMailHeader'] .
34 "From: $fromName <{$params['fromEmail']}>\n" .
35 "Reply-To: $fromName <{$params['replyTo']}>\n" .
36 "MIME-Version: 1.0\n" .
37 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
39 // assemble the final multipart message body with the text and html types included
40 $textBody = chunk_split(base64_encode($params['textVersion']));
41 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
42 $multipartMessageBody =
43 "--" . $mimeBoundary . "\n" . // plain text section
44 "Content-Type: text/plain; charset=UTF-8\n" .
45 "Content-Transfer-Encoding: base64\n\n" .
47 "--" . $mimeBoundary . "\n" . // text/html section
48 "Content-Type: text/html; charset=UTF-8\n" .
49 "Content-Transfer-Encoding: base64\n\n" .
51 "--" . $mimeBoundary . "--\n"; // message ending
55 'to' => $params['toEmail'],
56 'subject' => $messageSubject,
57 'body' => $multipartMessageBody,
58 'headers' => $messageHeader
60 call_hooks("emailer_send", $hookdata);
62 $hookdata['to'], // send to address
63 $hookdata['subject'], // subject
64 $hookdata['body'], // message body
65 $hookdata['headers'], // message headers
67 logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
68 logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);