2025-09-24 06:24:52 +00:00
< p align = "center" >
< a href = "https://github.com/yiisoft" target = "_blank" >
< img src = "https://yiisoft.github.io/docs/images/yii_logo.svg" height = "100px" >
< / a >
< h1 align = "center" > Yii Mailer Library - Symfony Mailer Extension< / h1 >
< br >
< / p >
This extension provides a [Symfony Mailer ](https://symfony.com/doc/5.4/mailer.html ) mail solution for [Yii framework 2.0 ](http://www.yiiframework.com ).
For license information check the [LICENSE ](LICENSE.md )-file.
[](https://packagist.org/packages/yiisoft/yii2-symfonymailer)
[](https://packagist.org/packages/yiisoft/yii2-symfonymailer)
[](https://github.com/yiisoft/yii2-symfonymailer/actions)
Installation
------------
The preferred way to install this extension is through [composer ](http://getcomposer.org/download/ ).
Either run
```
php composer.phar require --prefer-dist yiisoft/yii2-symfonymailer
```
or add
```json
2025-10-03 11:00:05 +00:00
"yiisoft/yii2-symfonymailer": "~2.0.0"
2025-09-24 06:24:52 +00:00
```
to the require section of your composer.json.
Usage
-----
To use this extension, simply add the following code in your application configuration:
```php
return [
//....
'components' => [
'mailer' => [
'class' => \yii\symfonymailer\Mailer::class,
'transport' => [
'scheme' => 'smtps',
'host' => '',
'username' => '',
'password' => '',
'port' => 465,
'dsn' => 'native://default',
],
'viewPath' => '@common/mail',
// send all mails to a file by default. You have to set
2025-10-03 11:00:05 +00:00
// 'useFileTransport' to false and configure transport
// for the mailer to send real emails.
'useFileTransport' => false,
2025-09-24 06:24:52 +00:00
],
],
];
```
or
```php
return [
//....
'components' => [
'mailer' => [
'class' => \yii\symfonymailer\Mailer::class,
'transport' => [
'dsn' => 'smtp://user:pass@smtp.example.com:25',
],
],
],
];
```
You can then send an email as follows:
```php
Yii::$app->mailer->compose('contact/html')
->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
```
Migrating from yiisoft/yii2-swiftmailer
---------------------------------------
To migrate from the deprecated [yiisoft/yii2-swiftmailer ](https://github.com/yiisoft/yii2-swiftmailer ) to this extension you need to update the application config.
2025-10-03 11:00:05 +00:00
Swiftmailer default transport was the `SendmailTransport` , while this extension will default to a `NullTransport` (sends no mail). You can use the swiftmailer default like the following:
2025-09-24 06:24:52 +00:00
```php
'mailer' => [
'class' => yii\symfonymailer\Mailer::class,
'transport' => [
'dsn' => 'sendmail://default',
],
],
```