3 use Friendica\Core\PConfig;
5 require_once('include/email.php');
9 * Send a multipart/alternative message with Text and HTML versions
11 * @param fromName name of the sender
12 * @param fromEmail email fo the sender
13 * @param replyTo replyTo address to direct responses
14 * @param toEmail destination email address
15 * @param messageSubject subject of the message
16 * @param htmlVersion html version of the message
17 * @param textVersion text only version of the message
18 * @param additionalMailHeader additions to the smtp mail header
19 * @param optional uid user id of the destination user
21 public static function send($params) {
23 call_hooks('emailer_send_prepare', $params);
25 $email_textonly = False;
26 if (x($params,"uid")) {
27 $email_textonly = PConfig::get($params['uid'], "system", "email_textonly");
30 $fromName = email_header_encode(html_entity_decode($params['fromName'],ENT_QUOTES,'UTF-8'),'UTF-8');
31 $messageSubject = email_header_encode(html_entity_decode($params['messageSubject'],ENT_QUOTES,'UTF-8'),'UTF-8');
33 // generate a mime boundary
34 $mimeBoundary =rand(0,9)."-"
35 .rand(100000000,999999999)."-"
36 .rand(100000000,999999999)."=:"
39 // generate a multipart/alternative message header
41 $params['additionalMailHeader'] .
42 "From: $fromName <{$params['fromEmail']}>\n" .
43 "Reply-To: $fromName <{$params['replyTo']}>\n" .
44 "MIME-Version: 1.0\n" .
45 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
47 // assemble the final multipart message body with the text and html types included
48 $textBody = chunk_split(base64_encode($params['textVersion']));
49 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
50 $multipartMessageBody =
51 "--" . $mimeBoundary . "\n" . // plain text section
52 "Content-Type: text/plain; charset=UTF-8\n" .
53 "Content-Transfer-Encoding: base64\n\n" .
56 if (!$email_textonly && !is_null($params['htmlVersion'])){
57 $multipartMessageBody .=
58 "--" . $mimeBoundary . "\n" . // text/html section
59 "Content-Type: text/html; charset=UTF-8\n" .
60 "Content-Transfer-Encoding: base64\n\n" .
63 $multipartMessageBody .=
64 "--" . $mimeBoundary . "--\n"; // message ending
68 'to' => $params['toEmail'],
69 'subject' => $messageSubject,
70 'body' => $multipartMessageBody,
71 'headers' => $messageHeader
73 //echo "<pre>"; var_dump($hookdata); killme();
74 call_hooks("emailer_send", $hookdata);
76 $hookdata['to'], // send to address
77 $hookdata['subject'], // subject
78 $hookdata['body'], // message body
79 $hookdata['headers'] // message headers
81 logger("header " . 'To: ' . $params['toEmail'] . "\n" . $messageHeader, LOGGER_DEBUG);
82 logger("return value " . (($res)?"true":"false"), LOGGER_DEBUG);