# MailerInterface

> MailerInterface is the interface that should be implemented by mailer classes.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [mail](/docs/api/yii/mail/index.md) › MailerInterface

| interface | `yii\mail\MailerInterface` |
| --- | --- |
| Since | 2.0 |
| Source | [`framework/mail/MailerInterface.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/mail/MailerInterface.php#L30) |

Implemented by 1 type:

- [`BaseMailer`](/docs/api/yii/mail/basemailer/index.md)

MailerInterface is the interface that should be implemented by mailer classes.

A mailer should mainly support creating and sending [mail messages](/docs/api/yii/mail/messageinterface/index.md). 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`](/docs/api/yii/mail/messageinterface/index.md).

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`compose()`](#method-compose) abstract | Creates a new message instance and optionally composes its body content via view rendering. | `MailerInterface` |
| [`send()`](#method-send) abstract | Sends the given email message. | `MailerInterface` |
| [`sendMultiple()`](#method-sendMultiple) abstract | Sends multiple messages at once. | `MailerInterface` |

## Method details

### compose() <span id="method-compose"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$view` | `string\|array\|null` | The view to be used for rendering the message body. This can be: - a string, which represents the view name or [path alias](/docs/guide/concept-aliases/index.md) 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. |
| `$params` | `array` | The parameters (name-value pairs) that will be extracted and made available in the view file. |

**Returns**

[`MessageInterface`](/docs/api/yii/mail/messageinterface/index.md): Message instance.

### send() <span id="method-send"></span>

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

Sends the given email message.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$message` | [`MessageInterface`](/docs/api/yii/mail/messageinterface/index.md) | Email message instance to be sent |

**Returns**

`bool`: Whether the message has been sent successfully

### sendMultiple() <span id="method-sendMultiple"></span>

```php
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**

| Parameter | Type | Description |
| --- | --- | --- |
| `$messages` | `array` | List of email messages, which should be sent. |

**Returns**

`int`: Number of messages that are successfully sent.