mimemail.mail.inc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. $mailengine = $engine . '_mailengine';
  29. $engine_prepare_message = $engine . '_prepare_message';
  30. if (function_exists($engine_prepare_message)) {
  31. $message = $engine_prepare_message($message);
  32. }
  33. else {
  34. $message = mimemail_prepare_message($message);
  35. }
  36. return $message;
  37. }
  38. /**
  39. * Send an HTML e-mail message, using Drupal variables and default settings.
  40. *
  41. * @param array $message
  42. * A message array, as described in hook_mail_alter() with optional
  43. * parameters described in mimemail_prepare_message().
  44. *
  45. * @return boolean
  46. * TRUE if the mail was successfully accepted, otherwise FALSE.
  47. */
  48. public function mail(array $message) {
  49. $engine = variable_get('mimemail_engine', 'mimemail');
  50. $mailengine = $engine . '_mailengine';
  51. if (!$engine || !function_exists($mailengine)) {
  52. return FALSE;
  53. }
  54. return $mailengine('send', $message);
  55. }
  56. }