Background mailer for Yii2 using any queue interface. This extension was tested with yii2 queue extension.
This extension was tested only with swiftmailer extension, though it should work with any compatible mailer extension
The preferred way to install this extension is through composer.
php composer.phar require --prefer-dist shaqman/yii2-queue-mailer
queue component of your application.
You can find the details here: https://github.com/yiisoft/yii2-queue/
\shaqman\mailer\queuemailer\Mailer as your primary mailer.
'mailer' => [ 'class' => \shaqman\mailer\queuemailer\Mailer::class, 'queue' => 'queue' // name of queue component, or a valid array configuration for it. 'syncMailer' => [ // Any valid mailer should work 'class' => 'yii\swiftmailer\Mailer', 'useFileTransport' => true, ], ],
Now you can send your emails as usual.
$message = \Yii::$app->mailer->compose() ->setSubject('test subject') ->setFrom('firstname.lastname@example.org') ->setHtmlBody('test body') ->setTo('email@example.com') ->send($message);
One small difference should be noted compared to the default
send. It now returns an
int identifying the queue id that the mail was assigned to.
This is to be expected since there is no way to know whether the mail was successfully sent at the time of the command was executed.