4 // send email notification if requested.
8 'notify_flags' => $importer['notify-flags'],
9 'language' => $importer['language'],
10 'to_name' => $importer['username'],
11 'to_email' => $importer['email'],
13 'source_name' => $msg['from-name'],
14 'source_link' => $importer['url'],
15 'source_photo' => $importer['thumb'],
18 //notification($notif_params);
21 function notification($params) {
23 logger('notification: entry');
26 $banner = t('Friendica Notification');
27 $product = FRIENDICA_PLATFORM;
29 $thanks = t('Thank You,');
30 $sitename = get_config('config','sitename');
31 $site_admin = sprintf( t('%s Administrator'), $sitename);
33 $sender_name = t('Administrator');
34 $sender_email = t('noreply') . '@' . $a->get_hostname();
36 $title = $params['item']['title'];
37 $body = $params['item']['body'];
39 if($params['type'] == NOTIFY_MAIL) {
41 logger('notification: email');
43 $subject = sprintf( t('New mail received at %s'),$sitename);
45 $preamble = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename);
47 $sitelink = t('Please visit %s to view and/or reply to your private messages.');
48 $tsitelink = sprintf( $sitelink, $siteurl . '/message' );
49 $hsitelink = sprintf( $sitelink, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
53 // send email notification if notification preferences permit
55 require_once('bbcode.php');
56 if(intval($params['notify_flags']) & intval($params['type'])) {
58 logger('notification: sending email');
60 push_lang($params['language']);
62 $textversion = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
63 $body))),ENT_QUOTES,'UTF-8'));
64 $htmlversion = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
67 // load the template for private message notifications
68 $tpl = get_markup_template('email_notify_html.tpl');
69 $email_html_body = replace_macros($tpl,array(
71 '$product' => $product,
72 '$preamble' => $preamble,
73 '$sitename' => $sitename,
74 '$siteurl' => $siteurl,
75 '$source_name' => $parama['source_name'],
76 '$source_link' => $params['source_link'],
77 '$source_photo' => $params['source_photo'],
78 '$username' => $params['to_name'],
79 '$hsitelink' => $hsitelink,
81 '$site_admin' => $site_admin,
82 '$title' => stripslashes($title),
83 '$htmlversion' => $htmlversion,
86 // load the template for private message notifications
87 $tpl = get_markup_template('email_notify_text.tpl');
88 $email_text_body = replace_macros($tpl,array(
90 '$product' => $product,
91 '$preamble' => $preamble,
92 '$sitename' => $sitename,
93 '$siteurl' => $siteurl,
94 '$source_name' => $parama['source_name'],
95 '$source_link' => $params['source_link'],
96 '$source_photo' => $params['source_photo'],
97 '$username' => $params['to_name'],
98 '$tsitelink' => $tsitelink,
100 '$site_admin' => $site_admin,
101 '$title' => stripslashes($title),
102 '$textversion' => $textversion,
105 logger('text: ' . $email_text_body);
107 // use the EmailNotification library to send the message
110 'fromName' => $sender_name,
111 'fromEmail' => $sender_email,
112 'replyTo' => $sender_email,
113 'toEmail' => $params['to_email'],
114 'messageSubject' => $subject,
115 'htmlVersion' => $email_html_body,
116 'textVersion' => $email_text_body
122 require_once('include/email.php');
126 * Send a multipart/alternative message with Text and HTML versions
128 * @param fromName name of the sender
129 * @param fromEmail email fo the sender
130 * @param replyTo replyTo address to direct responses
131 * @param toEmail destination email address
132 * @param messageSubject subject of the message
133 * @param htmlVersion html version of the message
134 * @param textVersion text only version of the message
136 static public function send($params) {
138 logger('enotify: send: ' . print_r($params,true));
139 $fromName = email_header_encode($params['fromName'],'UTF-8');
140 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
143 // generate a mime boundary
144 $mimeBoundary =rand(0,9)."-"
145 .rand(10000000000,9999999999)."-"
146 .rand(10000000000,9999999999)."=:"
149 // generate a multipart/alternative message header
151 "From: {$params['fromName']} <{$params['fromEmail']}>\n" .
152 "Reply-To: {$params['replyTo']}\n" .
153 "MIME-Version: 1.0\n" .
154 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
156 // assemble the final multipart message body with the text and html types included
157 $textBody = chunk_split(base64_encode($params['textVersion']));
158 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
159 $multipartMessageBody =
160 "--" . $mimeBoundary . "\n" . // plain text section
161 "Content-Type: text/plain; charset=UTF-8\n" .
162 "Content-Transfer-Encoding: base64\n\n" .
164 "--" . $mimeBoundary . "\n" . // text/html section
165 "Content-Type: text/html; charset=UTF-8\n" .
166 "Content-Transfer-Encoding: base64\n\n" .
168 "--" . $mimeBoundary . "--\n"; // message ending
172 $params['toEmail'], // send to address
173 $params['messageSubject'], // subject
174 $multipartMessageBody, // message body
175 $messageHeader // message headers
177 logger("sendTextHtmlEmail: returns " . $res, LOGGER_DEBUG);