]> git.mxchange.org Git - friendica.git/blob - include/enotify.php
Merge branch 'master' into notify
[friendica.git] / include / enotify.php
1 <?php
2
3
4
5
6 function notify_setup($type,$params) {
7
8         $a = get_app();
9         $banner = t('Friendica Notification');
10         $product = FRIENDICA_PLATFORM;
11         $siteurl = z_path();
12         $thanks = t('Thank You,');
13         $sitename = get_config('config','sitename');
14         $site_admin = sprintf( t('%s Administrator'), $sitename);
15
16         $sender_name = t('Administrator');
17         $sender_email = t('noreply') . '@' . $a->get_hostname(),
18
19         if($type === NOTIFICATION_MAIL) {
20                 $new_email = sprintf( t('%s sent you a new private message at %s.'),$params['from'],$sitename);
21                 $email_visit = t('Please visit %s to view and/or reply to your private messages.');
22                 $email_tlink = sprintf( $email_visit, $siteurl . '/message' );
23                 $email_hlink = sprintf( $email_visit, '<a href="' . $siteurl . '/message">' . $sitename . '</a>');
24         }
25
26 }
27
28
29 require_once('include/email.php');
30
31 class enotify {
32         /**
33          * Send a multipart/alternative message with Text and HTML versions
34          *
35          * @param fromName                      name of the sender
36          * @param fromEmail                     email fo the sender
37          * @param replyTo                       replyTo address to direct responses
38          * @param toEmail                       destination email address
39          * @param messageSubject        subject of the message
40          * @param htmlVersion           html version of the message
41          * @param textVersion           text only version of the message
42          */
43         static public function send($params) {
44                 $fromName = email_header_encode($params['fromName'],'UTF-8'); 
45                 $messageSubject = email_header_encode(params['messageSubject'],'UTF-8');
46                 
47                 
48                 // generate a mime boundary
49                 $mimeBoundary   =rand(0,9)."-"
50                                 .rand(10000000000,9999999999)."-"
51                                 .rand(10000000000,9999999999)."=:"
52                                 .rand(10000,99999);
53
54                 // generate a multipart/alternative message header
55                 $messageHeader =
56                         "From: {$params['fromName']} <{$params['fromEmail']}>\n" . 
57                         "Reply-To: {$params['replyTo']}\n" .
58                         "MIME-Version: 1.0\n" .
59                         "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
60
61                 // assemble the final multipart message body with the text and html types included
62                 $textBody       =       chunk_split(base64_encode($params['textVersion']));
63                 $htmlBody       =       chunk_split(base64_encode($params['htmlVersion']));
64                 $multipartMessageBody =
65                         "--" . $mimeBoundary . "\n" .                                   // plain text section
66                         "Content-Type: text/plain; charset=UTF-8\n" .
67                         "Content-Transfer-Encoding: base64\n\n" .
68                         $textBody . "\n" .
69                         "--" . $mimeBoundary . "\n" .                                   // text/html section
70                         "Content-Type: text/html; charset=UTF-8\n" .
71                         "Content-Transfer-Encoding: base64\n\n" .
72                         $htmlBody . "\n" .
73                         "--" . $mimeBoundary . "--\n";                                  // message ending
74
75                 // send the message
76                 $res = mail(
77                         $toEmail,                                                                               // send to address
78                         $messageSubject,                                                                // subject
79                         $multipartMessageBody,                                                  // message body
80                         $messageHeader                                                                  // message headers
81                 );
82                 logger("sendTextHtmlEmail: returns " . $res, LOGGER_DEBUG);
83         }
84 }
85 ?>