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) {
24 $banner = t('Friendica Notification');
25 $product = FRIENDICA_PLATFORM;
27 $thanks = t('Thank You,');
28 $sitename = get_config('config','sitename');
29 $site_admin = sprintf( t('%s Administrator'), $sitename);
31 $sender_name = t('Administrator');
32 $sender_email = t('noreply') . '@' . $a->get_hostname();
34 $title = $params['item']['title'];
35 $body = $params['item']['body'];
37 if($params['type'] == NOTIFY_MAIL) {
39 $subject = sprintf( t('New mail received at %s'),$sitename);
41 $preamble = sprintf( t('%s sent you a new private message at %s.'),$params['source_name'],$sitename);
42 $sitelink = t('Please visit %s to view and/or reply to your private messages.');
43 $tsitelink = sprintf( $email_visit, $siteurl . '/message' );
44 $hsitelink = sprintf( $email_visit, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
49 // send email notification if notification preferences permit
51 require_once('bbcode.php');
52 if(intval($params['notify-flags']) & intval($params['type'])) {
54 push_lang($params['language']);
57 $msg['fromname'] = $sender_name;
58 $msg['fromemail'] = $sender_email;
60 $msg['textversion'] = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n",
61 $body))),ENT_QUOTES,'UTF-8'));
62 $msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r","\\n\\n" ,"\\n"),
65 // load the template for private message notifications
66 $tpl = get_intltext_template('mail_received_html_body_eml.tpl');
67 $email_html_body_tpl = replace_macros($tpl,array(
68 '$username' => $importer['username'],
69 '$siteName' => $a->config['sitename'], // name of this site
70 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
71 '$thumb' => $importer['thumb'], // thumbnail url for sender icon
72 '$email' => $importer['email'], // email address to send to
73 '$url' => $importer['url'], // full url for the site
74 '$from' => $msg['from-name'], // name of the person sending the message
75 '$title' => stripslashes($msg['title']), // subject of the message
76 '$htmlversion' => $msg['htmlversion'], // html version of the message
77 '$mimeboundary' => $msg['mimeboundary'], // mime message divider
78 '$hostname' => $a->get_hostname() // name of this host
81 // load the template for private message notifications
82 $tpl = get_intltext_template('mail_received_text_body_eml.tpl');
83 $email_text_body_tpl = replace_macros($tpl,array(
84 '$username' => $importer['username'],
85 '$siteName' => $a->config['sitename'], // name of this site
86 '$siteurl' => $a->get_baseurl(), // descriptive url of this site
87 '$thumb' => $importer['thumb'], // thumbnail url for sender icon
88 '$email' => $importer['email'], // email address to send to
89 '$url' => $importer['url'], // full url for the site
90 '$from' => $msg['from-name'], // name of the person sending the message
91 '$title' => stripslashes($msg['title']), // subject of the message
92 '$textversion' => $msg['textversion'], // text version of the message
93 '$mimeboundary' => $msg['mimeboundary'], // mime message divider
94 '$hostname' => $a->get_hostname() // name of this host
97 // use the EmailNotification library to send the message
98 require_once("include/EmailNotification.php");
99 EmailNotification::sendTextHtmlEmail(
100 $msg['notificationfromname'],
101 $msg['notificationfromemail'],
102 $msg['notificationfromemail'],
105 $email_html_body_tpl,
112 require_once('include/email.php');
116 * Send a multipart/alternative message with Text and HTML versions
118 * @param fromName name of the sender
119 * @param fromEmail email fo the sender
120 * @param replyTo replyTo address to direct responses
121 * @param toEmail destination email address
122 * @param messageSubject subject of the message
123 * @param htmlVersion html version of the message
124 * @param textVersion text only version of the message
126 static public function send($params) {
127 $fromName = email_header_encode($params['fromName'],'UTF-8');
128 $messageSubject = email_header_encode($params['messageSubject'],'UTF-8');
131 // generate a mime boundary
132 $mimeBoundary =rand(0,9)."-"
133 .rand(10000000000,9999999999)."-"
134 .rand(10000000000,9999999999)."=:"
137 // generate a multipart/alternative message header
139 "From: {$params['fromName']} <{$params['fromEmail']}>\n" .
140 "Reply-To: {$params['replyTo']}\n" .
141 "MIME-Version: 1.0\n" .
142 "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
144 // assemble the final multipart message body with the text and html types included
145 $textBody = chunk_split(base64_encode($params['textVersion']));
146 $htmlBody = chunk_split(base64_encode($params['htmlVersion']));
147 $multipartMessageBody =
148 "--" . $mimeBoundary . "\n" . // plain text section
149 "Content-Type: text/plain; charset=UTF-8\n" .
150 "Content-Transfer-Encoding: base64\n\n" .
152 "--" . $mimeBoundary . "\n" . // text/html section
153 "Content-Type: text/html; charset=UTF-8\n" .
154 "Content-Transfer-Encoding: base64\n\n" .
156 "--" . $mimeBoundary . "--\n"; // message ending
160 $toEmail, // send to address
161 $messageSubject, // subject
162 $multipartMessageBody, // message body
163 $messageHeader // message headers
165 logger("sendTextHtmlEmail: returns " . $res, LOGGER_DEBUG);