PHPackages                             ratmir85/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. ratmir85/yii-swiftmailer

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

ratmir85/yii-swiftmailer
========================

The SwiftMailer integration for the Yii framework

v1.0.0(6y ago)01.5k↑55.6%BSD-3-ClausePHP

Since May 23Pushed 6y agoCompare

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

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

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

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

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

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

[](#installation)

Run

```
composer require ratmir85/yii-swiftmailer

```

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

[](#configuration)

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

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

example SMTP:

```
return [
    //....
    'components' => [
        'mailer' => [
            'class' => 'ratmir85\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']
            ]
        ],
    ],
];
```

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

```
