2017 © Pedro Peláez
 

yii2-extension yii2-mailqueue

Yii2 mail queue component for yii2-swiftmailer.

image

tigrov/yii2-mailqueue

Yii2 mail queue component for yii2-swiftmailer.

  • Wednesday, January 24, 2018
  • by Tigros
  • Repository
  • 1 Watchers
  • 6 Stars
  • 2,018 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 13 % Grown

The README.md

yii2-mailqueue

Yii2 mail queue component for yii2-symfonymailer., (*1)

Latest Stable Version, (*2)

Limitation

Since 1.1.6 requires PHP >= 8.1, (*3)

Installation

The preferred way to install this extension is through composer., (*4)

Either run, (*5)

php composer.phar require --prefer-dist tigrov/yii2-mailqueue "~1.1.1"

or add, (*6)

"tigrov/yii2-mailqueue": "~1.1.6"

to the require section of your composer.json file., (*7)

Configuration

Once the extension is installed, add following code to your application configuration:, (*8)

return [
    // ...
    'components' => [
        'mailer' => [
            'class' => 'tigrov\mailqueue\Mailer',
            'table' => '{{%mail_queue}}',
            'maxAttempts' => 5,
            'attemptIntervals' => [0, 'PT10M', 'PT1H', 'PT6H'],
            'removeFailed' => true,
            'maxPerPeriod' => 10,
            'periodSeconds' => 1,
        ],
    ],
    // ...
];

Following properties are available for customizing the mail queue behavior., (*9)

  • table name of the database table to store emails added to the queue;
  • maxAttempts maximum number of sending attempts per email;
  • attemptIntervals seconds or interval specifications to delay between attempts to send a mail message, see http://php.net/manual/en/dateinterval.construct.php;
  • removeFailed indicator to remove mail messages which were not sent in maxAttempts;
  • maxPerPeriod number of mail messages which could be sent per periodSeconds;
  • periodSeconds period in seconds which indicate the time interval for maxPerPeriod option.

Updating database schema

Run yii migrate command in command line:, (*10)

php yii migrate/up --migrationPath=@vendor/tigrov/yii2-mailqueue/src/migrations/

Sending the mail queue

To sending mails from the queue call Yii::$app->mailer->sending() or run the console command yii mailqueue which can be triggered by a CRON job:, (*11)

* * * * * php /var/www/vhosts/domain.com/yii mailqueue/sending

After the mail message successfully sent it will be deleted from the queue., (*12)

Usage

You can then send a mail to the queue as follows:, (*13)

Yii::$app->mailer->compose('contact/html')
     ->setFrom('from@domain.com')
     ->setTo($form->email)
     ->setSubject($form->subject)
     ->setTextBody($form->body)
     ->delay('PT3M') // seconds or an interval specification to delay of sending the mail message, see http://php.net/manual/en/dateinterval.construct.php
     ->unique('unique key') // a unique key for the mail message, new message with the same key will replace the old one
     ->queue();

You can still send mails directly with yii2-swiftmailer:, (*14)

Yii::$app->mailer->compose('contact/html')
     ->setFrom('from@domain.com')
     ->setTo($form->email)
     ->setSubject($form->subject)
     ->setTextBody($form->body)
     ->send();

License

MIT, (*15)

The Versions

24/01 2018

dev-master

9999999-dev https://github.com/tigrov/yii2-mailqueue

Yii2 mail queue component for yii2-swiftmailer.

  Sources   Download

MIT

The Requires

 

by Sergei Tigrov

mail email extension yii2 queue delay