MailerInterface.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\mail;
  8. /**
  9. * MailerInterface is the interface that should be implemented by mailer classes.
  10. *
  11. * A mailer should mainly support creating and sending [[MessageInterface|mail messages]]. It should
  12. * also support composition of the message body through the view rendering mechanism. For example,
  13. *
  14. * ```php
  15. * Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
  16. * ->setFrom('from@domain.com')
  17. * ->setTo($form->email)
  18. * ->setSubject($form->subject)
  19. * ->send();
  20. * ```
  21. *
  22. * @see MessageInterface
  23. *
  24. * @author Paul Klimov <klimov.paul@gmail.com>
  25. * @since 2.0
  26. */
  27. interface MailerInterface
  28. {
  29. /**
  30. * Creates a new message instance and optionally composes its body content via view rendering.
  31. *
  32. * @param string|array|null $view the view to be used for rendering the message body. This can be:
  33. *
  34. * - a string, which represents the view name or [path alias](guide:concept-aliases) for rendering the HTML body of the email.
  35. * In this case, the text body will be generated by applying `strip_tags()` to the HTML body.
  36. * - an array with 'html' and/or 'text' elements. The 'html' element refers to the view name or path alias
  37. * for rendering the HTML body, while 'text' element is for rendering the text body. For example,
  38. * `['html' => 'contact-html', 'text' => 'contact-text']`.
  39. * - null, meaning the message instance will be returned without body content.
  40. *
  41. * @param array $params the parameters (name-value pairs) that will be extracted and made available in the view file.
  42. * @return MessageInterface message instance.
  43. */
  44. public function compose($view = null, array $params = []);
  45. /**
  46. * Sends the given email message.
  47. * @param MessageInterface $message email message instance to be sent
  48. * @return bool whether the message has been sent successfully
  49. */
  50. public function send($message);
  51. /**
  52. * Sends multiple messages at once.
  53. *
  54. * This method may be implemented by some mailers which support more efficient way of sending multiple messages in the same batch.
  55. *
  56. * @param array $messages list of email messages, which should be sent.
  57. * @return int number of messages that are successfully sent.
  58. */
  59. public function sendMultiple(array $messages);
  60. }