]> git.mxchange.org Git - friendica.git/blob - include/EmailNotification.php
stuff to make connecting to diaspora profiles easier
[friendica.git] / include / EmailNotification.php
1 <?php
2 class EmailNotification {
3         /**
4          * Send a multipart/alternative message with Text and HTML versions
5          *
6          * @param fromName                      name of the sender
7          * @param fromEmail                     email fo the sender
8          * @param replyTo                       replyTo address to direct responses
9          * @param toEmail                       destination email address
10          * @param messageSubject        subject of the message
11          * @param htmlVersion           html version of the message
12          * @param textVersion           text only version of the message
13          */
14         static public function sendTextHtmlEmail($fromName,$fromEmail,$replyTo,$toEmail,$messageSubject,$htmlVersion,$textVersion) {
15                 logger("sendTextHtmlEmail: BEGIN");
16                 logger("fromName:       " . $fromName);
17                 logger("fromEmail:      " . $fromEmail);
18                 logger("replyTo:        " . $replyTo);
19                 logger("toEmail:        " . $toEmail);
20                 logger("messageSubject: " . $messageSubject);
21                 //logger("htmlVersion:    " . $htmlVersion);
22                 //logger("textVersion:    " . $textVersion);
23                 
24                 // generate a mime boundary
25                 $mimeBoundary   =rand(0,9)."-"
26                                 .rand(10000000000,9999999999)."-"
27                                 .rand(10000000000,9999999999)."=:"
28                                 .rand(10000,99999);
29
30                 // generate a multipart/alternative message header
31                 $messageHeader =
32                         "From: {$fromName} <{$fromEmail}>\n" . 
33                         "Reply-To: {$replyTo}\n" .
34                         "MIME-Version: 1.0\n" .
35                         "Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
36
37                 // assemble the final multipart message body with the text and html types included
38                 $textBody       =       chunk_split(base64_encode($textVersion));
39                 $htmlBody       =       chunk_split(base64_encode($htmlVersion));
40                 $multipartMessageBody =
41                         "--" . $mimeBoundary . "\n" .                                   // plain text section
42                         "Content-Type: text/plain; charset=UTF-8\n" .
43                         "Content-Transfer-Encoding: base64\n\n" .
44                         $textBody . "\n" .
45                         "--" . $mimeBoundary . "\n" .                                   // text/html section
46                         "Content-Type: text/html; charset=UTF-8\n" .
47                         "Content-Transfer-Encoding: base64\n\n" .
48                         $htmlBody . "\n" .
49                         "--" . $mimeBoundary . "--\n";                                  // message ending
50
51                 // send the message
52                 $res = mail(
53                         $toEmail,                                                                               // send to address
54                         $messageSubject,                                                                // subject
55                         $multipartMessageBody,                                                  // message body
56                         $messageHeader                                                                  // message headers
57                 );
58                 logger("sendTextHtmlEmail: END");
59         }
60 }
61 ?>