Yii 2.0: yii2-spoolmailer

SwiftMailer Extension for Yii 2 with Spooling
1 follower

Implements email queue using SwiftMailer spool transport and yii2-swiftmailer extension.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist izumi-kun/yii2-spoolmailer "*"

or add

"izumi-kun/yii2-spoolmailer": "*"

to the require section of your composer.json.

Usage

To use this extension, simply add the following code in your application configuration (both web and console):

return [
    //....
    'components' => [
        'mailer' => [
            'class' => 'izumi\spoolmailer\Mailer',
        ],
    ],
];

Add the following code in your console configuration:

return [
    //....
    'controllerMap' => [
        'mail' => 'izumi\spoolmailer\MailController',
    ],
];

You can then add an email in queue as follows:

Yii::$app->mailer->compose('contact/html')
     ->setFrom('from@domain.com')
     ->setTo($form->email)
     ->setSubject($form->subject)
     ->queue();

Process email queue by follow console command:

./yii mail/flush

CRON job:

*/5 * * * * php /var/www/yii-app/yii mail/flush >/dev/null 2>&1

Since this extension extends yii2-swiftmailer for further instructions refer to the related section in the Yii Definitive Guide.

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet