PHPackages                             xeois/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. xeois/yii2-mailqueue

ActiveYii2-extension

xeois/yii2-mailqueue
====================

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

01551PHP

Since Feb 23Pushed 6y ago2 watchersCompare

[ Source](https://github.com/xeois/yii2-mailqueue)[ Packagist](https://packagist.org/packages/xeois/yii2-mailqueue)[ RSS](/packages/xeois-yii2-mailqueue/feed)WikiDiscussions master Synced 1mo ago

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 xeois/yii2-mailqueue "*"

```

or add

```
"xeois/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' => 'xeois\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' => 'xeois\mailqueue\MailQueue',
			'table' => '{{%mail_queue}}',
        ],
    ],
];
```

then run `yii migrate` command in command line:

```
php yii migrate/up --migrationPath=@vendor/xeois/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 `xeois\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' => 'xeois\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` and also add to db for reference:

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

License
-------

[](#license)

[MIT](LICENSE)

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

[](#yii2-mailqueue-1)

enhance version of nterms/yii2-mailque to send and queue. Email queue component for yii2 that works with yii2-swiftmailer.

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity34

Early-stage or recently created project

 Bus Factor1

Top contributor holds 66.7% 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/d2487df0c8eee3ef90a40fa6c0e1248c6fd6d0da0c20eb8625d0701d5739e605?d=identicon)[vikramsra](/maintainers/vikramsra)

![](https://www.gravatar.com/avatar/cecbafa8e14b499f01dbfc8cd6f1d2896888c7c3e6bc6fecd604317ca0285080?d=identicon)[mhussain001](/maintainers/mhussain001)

---

Top Contributors

[![mhussain001](https://avatars.githubusercontent.com/u/1640875?v=4)](https://github.com/mhussain001 "mhussain001 (2 commits)")[![vikramsra](https://avatars.githubusercontent.com/u/1715752?v=4)](https://github.com/vikramsra "vikramsra (1 commits)")

### Embed Badge

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

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

PHPackages © 2026

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