]> git.mxchange.org Git - friendica.git/blob - include/EmailNotification.php
Merge branch 'master', remote-tracking branch 'remotes/upstream/master'
[friendica.git] / include / EmailNotification.php
1 <?php
2
3 require_once('include/email.php');
4
5 class EmailNotification {
6         /**
7          * Send a multipart/alternative message with Text and HTML versions
8          *
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          */
17         static public function sendTextHtmlEmail($fromName,$fromEmail,$replyTo,$toEmail,$messageSubject,$htmlVersion,$textVersion) {
18
19                 $fromName = email_header_encode($fromName,'UTF-8'); 
20                 $messageSubject = email_header_encode($messageSubject,'UTF-8');
21                 
22                 
23                 // generate a mime boundary
24                 $mimeBoundary   =rand(0,9)."-"
25                                 .rand(10000000000,9999999999)."-"
26                                 .rand(10000000000,9999999999)."=:"
27                                 .rand(10000,99999);
28
29                 // generate a multipart/alternative message header
30                 $messageHeader =
31                         "From: {$fromName} <{$fromEmail}>\n" . 
32                         "Reply-To: {$replyTo}\n" .
33                         "MIME-Version: 1.0\n" .
34                         "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
35
36                 // assemble the final multipart message body with the text and html types included
37                 $textBody       =       chunk_split(base64_encode($textVersion));
38                 $htmlBody       =       chunk_split(base64_encode($htmlVersion));
39                 $multipartMessageBody =
40                         "--" . $mimeBoundary . "\n" .                                   // plain text section
41                         "Content-Type: text/plain; charset=UTF-8\n" .
42                         "Content-Transfer-Encoding: base64\n\n" .
43                         $textBody . "\n" .
44                         "--" . $mimeBoundary . "\n" .                                   // text/html section
45                         "Content-Type: text/html; charset=UTF-8\n" .
46                         "Content-Transfer-Encoding: base64\n\n" .
47                         $htmlBody . "\n" .
48                         "--" . $mimeBoundary . "--\n";                                  // message ending
49
50                 // send the message
51                 $res = mail(
52                         $toEmail,                                                                               // send to address
53                         $messageSubject,                                                                // subject
54                         $multipartMessageBody,                                                  // message body
55                         $messageHeader                                                                  // message headers
56                 );
57                 logger("sendTextHtmlEmail: END");
58         }
59 }
60 ?>