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 $email_textonly = False;
24 if (x($params,"uid")) {
25 $email_textonly = get_pconfig($params['uid'], "system", "email_textonly");
28 $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
29 $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
31 // generate a mime boundary
32 $mimeBoundary =rand(0,9)."-"
33 .rand(100000000,999999999)."-"
34 .rand(100000000,999999999)."=:"
37 // generate a multipart/alternative message header
39 $params['additionalMailHeader'] .
40 "From: $fromName <{$params['fromEmail']}>\n" .
41 "Reply-To: $fromName <{$params['replyTo']}>\n" .
42 "MIME-Version: 1.0\n" .
43 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
45 // assemble the final multipart message body with the text and html types included
46 $textBody = chunk_split(base64_encode($params['textVersion']));
47 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
48 $multipartMessageBody =
49 "--" . $mimeBoundary . "\n" . // plain text section
50 "Content-Type: text/plain; charset=UTF-8\n" .
51 "Content-Transfer-Encoding: base64\n\n" .
54 if (!$email_textonly && !is_null($params['htmlVersion'])){
55 $multipartMessageBody .=
56 "--" . $mimeBoundary . "\n" . // text/html section
57 "Content-Type: text/html; charset=UTF-8\n" .
58 "Content-Transfer-Encoding: base64\n\n" .
61 $multipartMessageBody .=
62 "--" . $mimeBoundary . "--\n"; // message ending
66 'to' => $params['toEmail'],
67 'subject' => $messageSubject,
68 'body' => $multipartMessageBody,
69 'headers' => $messageHeader
71 //echo "<pre>"; var_dump($hookdata); killme();
72 call_hooks("emailer_send", $hookdata);
74 $hookdata['to'], // send to address
75 $hookdata['subject'], // subject
76 $hookdata['body'], // message body
77 $hookdata['headers'] // message headers
79 logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
80 logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);