QueueMails
Installation
The preferred way to install this extension is through composer., (*1)
Either run, (*2)
php composer.phar require --prefer-dist vision/yii2-private-messages "@dev"
or add to the require section of your composer.json file., (*3)
"vision/yii2-queue-mails":"~1.0.0"
Configuration
Once the extension is installed, add following code to your application configuration :, (*4)
'mailer' => [
'class' => 'vision\queue_mails\Mailer',
'mailsPerRound' => 5,
'realMailer' => [
'class' => '****',
'apikey' => '*****'
]
],
, (*5)
and /config/console.php:, (*6)
'mailer' => [
'class' => 'vision\queue_mails\Mailer',
'mailsPerRound' => 5,
'realMailer' => [
'class' => '****',
'apikey' => '*****'
]
],
, (*7)
Following properties are available for customizing the mail queue behavior., (*8)
mailsPerRound: Number of emails to send at a time., (*9)
Run yii migrate command in command line:, (*10)
php yii migrate --migrationPath=@vendor/vision/yii2-queue-mails/migrations, (*11)
Most preferably this could be a console command (eg: mail/send) which can be triggered by a CRON job.
Setting the CRON job, (*12)
Set a CRON job to run console command:, (*13)
*/10 * * * * php /var/www/html/myapp/yii mail/send
, (*14)
Usage
Yii::$app->mailer->compose('contact/html', ['contactForm' => $form])
->setFrom('from@domain.com')
->setTo($form->email)
->setSubject($form->subject)
->send();
, (*15)
Processing the mail queue
Now calling Yii::$app->mailqueue->process() will process the message queue and send out the emails., (*16)