izumi-kun / yii2-spoolmailer
Implements email queue using SwiftMailer spool transport and yii2-swiftmailer extension
Installs: 3 836
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 3
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- php: >=7.0.0
- yiisoft/yii2: ~2.0.13
- yiisoft/yii2-swiftmailer: ~2.1.0
Requires (Dev)
- phpunit/phpunit: ~6.4.0
- symfony/process: *
- yiisoft/yii2-queue: ~2.0.0
Suggests
- yiisoft/yii2-queue: Need for QueueSpool.
This package is auto-updated.
Last update: 2024-11-15 05:53:23 UTC
README
Implements email queue using SwiftMailer spool transport and yii2-swiftmailer extension.
It supported queues based on built-in SwiftMailer spools or Yii2 Queue 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": "~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