Skip to content
PHP Ecosystem
Explore

MailerInterface

API reference › yii › mail › MailerInterface

interfaceyii\mail\MailerInterface
Since2.0
Sourceframework/mail/MailerInterface.php
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.

MethodDescriptionDefined by
compose() abstractCreates a new message instance and optionally composes its body content via view rendering.MailerInterface
send() abstractSends the given email message.MailerInterface
sendMultiple() abstractSends multiple messages at once.MailerInterface
abstract public function compose(string|array|null $view = null, array $params = []): yii\mail\MessageInterface

Creates a new message instance and optionally composes its body content via view rendering.

Parameters

ParameterTypeDescription
$viewstring|array|nullThe 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', 'text' => 'contact-text']. - null, meaning the message instance will be returned without body content.
$paramsarrayThe parameters (name-value pairs) that will be extracted and made available in the view file.

Returns

MessageInterface: Message instance.

abstract public function send(yii\mail\MessageInterface $message): bool

Sends the given email message.

Parameters

ParameterTypeDescription
$messageMessageInterfaceEmail message instance to be sent

Returns

bool: Whether the message has been sent successfully

abstract public function sendMultiple(array $messages): int

Sends 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

ParameterTypeDescription
$messagesarrayList of email messages, which should be sent.

Returns

int: Number of messages that are successfully sent.