mimemail.mail.inc 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * @file
  4. * Mime Mail implementations of MailSystemInterface.
  5. */
  6. /**
  7. * Modify the Drupal mail system to send HTML emails.
  8. */
  9. class MimeMailSystem implements MailSystemInterface {
  10. /**
  11. * Concatenate and wrap the e-mail body for HTML mails.
  12. *
  13. * @param array $message
  14. * A message array, as described in hook_mail_alter() with optional
  15. * parameters described in mimemail_prepare_message().
  16. *
  17. * @return array
  18. * The formatted $message.
  19. */
  20. public function format(array $message) {
  21. if (is_array($message['body'])) {
  22. $message['body'] = implode("\n\n", $message['body']);
  23. }
  24. if (preg_match('/plain/', $message['headers']['Content-Type'])) {
  25. $message['body'] = check_markup($message['body'], variable_get('mimemail_format', filter_fallback_format()));
  26. }
  27. $engine = variable_get('mimemail_engine', 'mimemail');
  28. $engine_prepare_message = $engine . '_prepare_message';
  29. if (function_exists($engine_prepare_message)) {
  30. $message = $engine_prepare_message($message);
  31. }
  32. else {
  33. $message = mimemail_prepare_message($message);
  34. }
  35. return $message;
  36. }
  37. /**
  38. * Send an HTML e-mail message, using Drupal variables and default settings.
  39. *
  40. * @param array $message
  41. * A message array, as described in hook_mail_alter() with optional
  42. * parameters described in mimemail_prepare_message().
  43. *
  44. * @return boolean
  45. * TRUE if the mail was successfully accepted, otherwise FALSE.
  46. */
  47. public function mail(array $message) {
  48. $engine = variable_get('mimemail_engine', 'mimemail');
  49. $mailengine = $engine . '_mailengine';
  50. if (!$engine || !function_exists($mailengine)) {
  51. return FALSE;
  52. }
  53. return $mailengine('send', $message);
  54. }
  55. }