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
17 * @param optional uid user id of the destination user
19 static public function send($params) {
21 call_hooks('emailer_send_prepare', $params);
23 $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
24 $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
26 // generate a mime boundary
27 $mimeBoundary =rand(0,9)."-"
28 .rand(10000000000,9999999999)."-"
29 .rand(10000000000,9999999999)."=:"
32 // generate a multipart/alternative message header
34 $params['additionalMailHeader'] .
35 "From: $fromName <{$params['fromEmail']}>\n" .
36 "Reply-To: $fromName <{$params['replyTo']}>\n" .
37 "MIME-Version: 1.0\n" .
38 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
40 // assemble the final multipart message body with the text and html types included
41 $textBody = chunk_split(base64_encode($params['textVersion']));
42 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
43 $multipartMessageBody =
44 "--" . $mimeBoundary . "\n" . // plain text section
45 "Content-Type: text/plain; charset=UTF-8\n" .
46 "Content-Transfer-Encoding: base64\n\n" .
48 "--" . $mimeBoundary . "\n" . // text/html section
49 "Content-Type: text/html; charset=UTF-8\n" .
50 "Content-Transfer-Encoding: base64\n\n" .
52 "--" . $mimeBoundary . "--\n"; // message ending
56 'to' => $params['toEmail'],
57 'subject' => $messageSubject,
58 'body' => $multipartMessageBody,
59 'headers' => $messageHeader
61 call_hooks("emailer_send", $hookdata);
63 $hookdata['to'], // send to address
64 $hookdata['subject'], // subject
65 $hookdata['body'], // message body
66 $hookdata['headers'] // message headers
68 logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
69 logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);