PHPackages                             bashkarev/yii-swiftmailer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. bashkarev/yii-swiftmailer

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

bashkarev/yii-swiftmailer
=========================

The SwiftMailer integration for the Yii framework

1.0.0(9y ago)35.9k↓50%2BSD-3-ClausePHP

Since Jul 14Pushed 9y ago1 watchersCompare

[ Source](https://github.com/bashkarev/yii-swiftmailer)[ Packagist](https://packagist.org/packages/bashkarev/yii-swiftmailer)[ RSS](/packages/bashkarev-yii-swiftmailer/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

SwiftMailer Extension for Yii1, imported yii2-swiftmailer
=========================================================

[](#swiftmailer-extension-for-yii1-imported-yii2-swiftmailer)

This extension provides a [SwiftMailer](http://swiftmailer.org/) mail solution for [Yii framework 1](http://www.yiiframework.com).

Installation
------------

[](#installation)

Either run

```
composer require bashkarev/yii-swiftmailer

```

or add

```
"bashkarev/yii-swiftmailer": "~1.0.0"
```

to the require section of your composer.json.

Configuration
-------------

[](#configuration)

Mail component configuration depends on the extension you have chosen. In general your application configuration should look like:

```
return [
    //....
    'components' => [
        'mailer' => [
            'class' => 'bashkarev\swiftmailer\swift\Mailer',
        ],
    ],
];
```

example SMTP:

```
return [
    //....
    'components' => [
        'mailer' => [
            'class' => 'bashkarev\swiftmailer\swift\Mailer',
            //'viewPath' => 'application.mail' //default path to views
            'transport' => [
                'host' => 'smtp.example.ru.',
                'username' => 'username',
                'password' => 'password',
                'port' => '465',
                'encryption' => 'ssl',
            ],
            'messageConfig' => [
                'from' => ['example@example.ru' => 'Example Name']
            ]
        ],
    ],
];
```

Debug panel
-----------

[](#debug-panel)

usage panel [zhuravljov/yii2-debug](https://github.com/zhuravljov/yii2-debug)

```
return [
    //....
    'components' => [
        'debug' => [
            'class' => 'application.vendor.zhuravljov.yii2-debug.Yii2Debug',
            'enabled' => YII_DEBUG,
            'panels' =>[
                'mail' => [
                    'class' => 'bashkarev\swiftmailer\debug\MailPanel'
                ]
            ],
        ],
    ],
];
```

Basic usage
-----------

[](#basic-usage)

Once the 'mailer' component is configured, you can use the following code to send an email message:

```
Yii::app()->mailer->compose()
    ->setFrom('from@domain.com')
    ->setTo('to@domain.com')
    ->setSubject('Message subject')
    ->setTextBody('Plain text content')
    ->setHtmlBody('HTML content')
    ->send();
```

You may also send several messages at once:

```
$messages = [];
foreach ($users as $user) {
    $messages[] = Yii::app()->mailer->compose()
        // ...
        ->setTo($user->email);
}
Yii::$app->mailer->sendMultiple($messages);
```

Composing mail content
----------------------

[](#composing-mail-content)

Yii allows composition of the actual mail messages content via special view files. By default these files should be located at 'application.mail' path.

Example mail view file layout: /protected/mail/layouts/html.php

```
