PHPackages                             adantart/yii2-mailqueue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. adantart/yii2-mailqueue

ActiveYii2-extension[Mail &amp; Notifications](/categories/mail)

adantart/yii2-mailqueue
=======================

Email queue component for yii2 that works with yii2-swiftmailer.

038PHP

Since Sep 18Pushed 6y ago1 watchersCompare

[ Source](https://github.com/adantart/yii2-mailqueue)[ Packagist](https://packagist.org/packages/adantart/yii2-mailqueue)[ RSS](/packages/adantart-yii2-mailqueue/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-mailqueue
==============

[](#yii2-mailqueue)

Email queue component for yii2 that works with [yii2-swiftmailer](http://www.yiiframework.com/doc-2.0/ext-swiftmailer-index.html)

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist dantart/yii2-mailqueue "*"

```

or add

```
"dantart/yii2-mailqueue": "*"

```

to the require section of your `composer.json` file.

Configuration
-------------

[](#configuration)

Once the extension is installed, add following code to your application configuration :

```
return [
    //....
    'components' => [
        'mailqueue' => [
            'class' => 'dantart\mailqueue\MailQueue',
			'table' => '{{%mail_queue}}',
			'mailsPerRound' => 10,
			'maxAttempts' => 3,
        ],
    ],
];
```

Following properties are available for customizing the mail queue behavior.

- `table`: Name of the database table to store emails added to the queue.
- `mailsPerRound`: Number of emails to send at a time.
- `maxAttempts`: Maximum number of sending attempts per email.

Updating database schema
------------------------

[](#updating-database-schema)

Apply the database migration to create the table required to store the mail queue messages. To do this, add following code to `/config/console.php`:

```
return [
    //....
    'components' => [
        'mailqueue' => [
            'class' => 'dantart\mailqueue\MailQueue',
			'table' => '{{%mail_queue}}',
        ],
    ],
];
```

then run `yii migrate` command in command line:

```
php yii migrate/up --migrationPath=@vendor/dantart/yii2-mailqueue/migrations/

```

Processing the mail queue
-------------------------

[](#processing-the-mail-queue)

Now calling `process()` on `Yii::$app->mailqueue` will process the message queue and send out the emails. In one of your controller actions:

```
public function actionSend()
{
	Yii::$app->mailqueue->process();
}
```

Most preferably this could be a console command (eg: mail/send) which can be triggered by a CRON job.

Setting the CRON job
--------------------

[](#setting-the-cron-job)

Set a CRON job to run console command:

```

*/10 * * * * php /var/www/html/myapp/yii mailqueue/process

```

Usage
-----

[](#usage)

You can then send an email to the queue as follows:

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

While `dantart\mailqueue\MailQueue` extends from `yii\swiftmailer\Mailer`, you can replace it with this extension by adding `yii2-swiftmailer` configuations directly to `mailqueue` configurations as follows:

```
return [
    //....
    'components' => [
        'mailqueue' => [
            'class' => 'dantart\mailqueue\MailQueue',
			'table' => '{{%mail_queue}}',
			'mailsPerRound' => 10,
			'maxAttempts' => 3,
			'transport' => [
				'class' => 'Swift_SmtpTransport',
				'host' => 'localhost',
				'username' => 'username',
				'password' => 'password',
				'port' => '587',
				'encryption' => 'tls',
			],
        ],
    ],
];
```

And use following code for directly sending emails as you ususally do with `yii2-swiftmailer`:

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

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/647a0856cbc78cd2f38932ee3bb48f7791d16211f933f476a5e3cd3ef3acce7a?d=identicon)[dantart](/maintainers/dantart)

---

Top Contributors

[![adantart](https://avatars.githubusercontent.com/u/695272?v=4)](https://github.com/adantart "adantart (2 commits)")

### Embed Badge

![Health badge](/badges/adantart-yii2-mailqueue/health.svg)

```
[![Health](https://phpackages.com/badges/adantart-yii2-mailqueue/health.svg)](https://phpackages.com/packages/adantart-yii2-mailqueue)
```

###  Alternatives

[tijsverkoyen/css-to-inline-styles

CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.

5.8k505.3M227](/packages/tijsverkoyen-css-to-inline-styles)[minishlink/web-push

Web Push library for PHP

1.9k12.0M53](/packages/minishlink-web-push)[laravel-notification-channels/twilio

Provides Twilio notification channel for Laravel

2587.7M12](/packages/laravel-notification-channels-twilio)[spatie/url-signer

Generate a url with an expiration date and signature to prevent unauthorized access

4422.3M16](/packages/spatie-url-signer)[mattketmo/email-checker

Throwaway email detection library

2742.0M5](/packages/mattketmo-email-checker)[laravel-notification-channels/discord

Laravel notification driver for Discord.

2371.3M11](/packages/laravel-notification-channels-discord)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
