MailerInterface
API reference › yii › mail › MailerInterface
Implemented by 1 type
MailerInterface is the interface that should be implemented by mailer classes.
A mailer should mainly support creating and sending mail messages. It should also support composition of the message body through the view rendering mechanism. For example,
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form]) ->setFrom('from@domain.com') ->setTo($form->email) ->setSubject($form->subject) ->send();See also: MessageInterface.
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
compose() abstract | Creates a new message instance and optionally composes its body content via view rendering. | MailerInterface |
send() abstract | Sends the given email message. | MailerInterface |
sendMultiple() abstract | Sends multiple messages at once. | MailerInterface |
Method details
Section titled “Method details”compose()
Section titled “compose() ”abstract public function compose(string|array|null $view = null, array $params = []): yii\mail\MessageInterfaceCreates a new message instance and optionally composes its body content via view rendering.
Parameters
| Parameter | Type | Description |
|---|---|---|
$view | string| | The view to be used for rendering the message body. This can be: - a string, which represents the view name or path alias for rendering the HTML body of the email. In this case, the text body will be generated by applying strip_tags() to the HTML body. - an array with ‘html’ and/or ‘text’ elements. The ‘html’ element refers to the view name or path alias for rendering the HTML body, while ‘text’ element is for rendering the text body. For example, ['html' => 'contact-html',. - null, meaning the message instance will be returned without body content. |
$params | array | The parameters (name-value pairs) that will be extracted and made available in the view file. |
Returns
MessageInterface: Message instance.
send()
Section titled “send() ”abstract public function send(yii\mail\MessageInterface $message): boolSends the given email message.
Parameters
| Parameter | Type | Description |
|---|---|---|
$message | MessageInterface | Email message instance to be sent |
Returns
bool: Whether the message has been sent successfully
sendMultiple()
Section titled “sendMultiple() ”abstract public function sendMultiple(array $messages): intSends multiple messages at once.
This method may be implemented by some mailers which support more efficient way of sending multiple messages in the same batch.
Parameters
| Parameter | Type | Description |
|---|---|---|
$messages | array | List of email messages, which should be sent. |
Returns
int: Number of messages that are successfully sent.