Skip to content

Latest commit

 

History

History
66 lines (47 loc) · 1.86 KB

README.md

File metadata and controls

66 lines (47 loc) · 1.86 KB

Queue mailer decorator for Yii2 framework

Send your emails in the background using Yii2 queues.

Build Status Latest Stable Version Total Downloads License

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist yarcode/yii2-queue-mailer

or add

"yarcode/yii2-queue-mailer": "*"

Usage

Configure queue component of your application. You can find the details here: https://www.yiiframework.com/extension/yiisoft/yii2-queue

Configure YarCode\Yii2\QueueMailer\Mailer as your primary mailer.

  'mailer' => [
      'class' => \YarCode\Yii2\QueueMailer\Mailer::class,
      'syncMailer' => [
          'class' => \yii\swiftmailer\Mailer::class,
          'useFileTransport' => true,
      ],
  ],

Now you can send your emails as usual.

$message = \Yii::$app->mailer->compose()
  ->setSubject('test subject')
  ->setFrom('[email protected]')
  ->setHtmlBody('test body')
  ->setTo('[email protected]');

\Yii::$app->mailer->send($message);

You can also get a background job ID of the last send() or sendMultiple() call.

$jobId = \Yii::$app->mailer->getLastJobId();

Licence

MIT

Links