Friendica Communications Platform (please note that this is a clone of the repository at github, issues are handled there) https://friendi.ca
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
2.0 KiB

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