MailInterface.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Drupal\Core\Mail;
  3. /**
  4. * Defines an interface for pluggable mail back-ends.
  5. *
  6. * @see \Drupal\Core\Annotation\Mail
  7. * @see \Drupal\Core\Mail\MailManager
  8. * @see plugin_api
  9. */
  10. interface MailInterface {
  11. /**
  12. * Formats a message prior to sending.
  13. *
  14. * Allows to preprocess, format, and postprocess a mail message before it is
  15. * passed to the sending system. By default, all messages may contain HTML and
  16. * are converted to plain-text by the Drupal\Core\Mail\Plugin\Mail\PhpMail
  17. * implementation. For example, an alternative implementation could override
  18. * the default implementation and also sanitize the HTML for usage in a MIME-
  19. * encoded email, but still invoking the Drupal\Core\Mail\Plugin\Mail\PhpMail
  20. * implementation to generate an alternate plain-text version for sending.
  21. *
  22. * @param array $message
  23. * A message array, as described in hook_mail_alter().
  24. *
  25. * @return array
  26. * The formatted $message.
  27. *
  28. * @see \Drupal\Core\Mail\MailManagerInterface
  29. */
  30. public function format(array $message);
  31. /**
  32. * Sends a message composed by \Drupal\Core\Mail\MailManagerInterface->mail().
  33. *
  34. * @param array $message
  35. * Message array with at least the following elements:
  36. * - id: A unique identifier of the email type. Examples: 'contact_user_copy',
  37. * 'user_password_reset'.
  38. * - to: The mail address or addresses where the message will be sent to.
  39. * The formatting of this string will be validated with the
  40. * @link http://php.net/manual/filter.filters.validate.php PHP email validation filter. @endlink
  41. * Some examples:
  42. * - user@example.com
  43. * - user@example.com, anotheruser@example.com
  44. * - User <user@example.com>
  45. * - User <user@example.com>, Another User <anotheruser@example.com>
  46. * - subject: Subject of the email to be sent. This must not contain any
  47. * newline characters, or the mail may not be sent properly. The subject
  48. * is converted to plain text by the mail plugin manager.
  49. * - body: Message to be sent. Accepts both CRLF and LF line-endings.
  50. * Email bodies must be wrapped. For smart plain text wrapping you can use
  51. * \Drupal\Core\Mail\MailFormatHelper::wrapMail() .
  52. * - headers: Associative array containing all additional mail headers not
  53. * defined by one of the other parameters. PHP's mail() looks for Cc and
  54. * Bcc headers and sends the mail to addresses in these headers too.
  55. *
  56. * @return bool
  57. * TRUE if the mail was successfully accepted for delivery, otherwise FALSE.
  58. */
  59. public function mail(array $message);
  60. }