Yii 2.0: yii2-spoolmailer

SwiftMailer Extension for Yii 2 with Spooling
1 follower

SwiftMailer Extension for Yii 2 with Spooling

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

It supported queues based on built-in SwiftMailer spools or Yii2 Queue Extension.

Latest Stable Version Total Downloads Build Status Scrutinizer Code Quality Code Coverage

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": "~1.0.0"

to the require section of your composer.json.

Basic Usage

This way uses built-in SwiftMailer spools: FileSpool (default) or MemorySpool.

Add the following code in your application configuration (both web and console):

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

Add the following code in your console configuration:

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

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:

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

Advanced Usage

This way requires Yii2 Queue Extension in your application.

Add the following code in your application configuration (both web and console):

return [
    //....
    'components' => [
        //....
        'mailer' => [
            'class' => izumi\spoolmailer\Mailer::class,
            'spoolMailer' => [
                'class' => izumi\spoolmailer\spools\QueueSpool::class,
                'queue' => 'queue', // the application component ID of the queue object
            ],
        ],
    ],
];

For more details see the Yii2 Queue Guide.

License

BSD-3-Clause

Be the first person to leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet