PHPackages                             codexten/yii-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. codexten/yii-mailqueue

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

codexten/yii-mailqueue
======================

Codexten Yii Mailer

176PHP

Since Mar 16Pushed 7y ago1 watchersCompare

[ Source](https://github.com/codexten/yii-mailqueue)[ Packagist](https://packagist.org/packages/codexten/yii-mailqueue)[ RSS](/packages/codexten-yii-mailqueue/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

yii-mailqueue
=============

[](#yii-mailqueue)

Yii mailqueue for Yii 2.0 or higher

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

```

or add

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

then run `yii migrate` command in command line:

```
php yii migrate/up --migrationPath=@vendor/nterms/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 `nterms\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' => 'nterms\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

21

—

LowBetter than 18% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity38

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/0086bda614ea92d9de2b79e87cb1ed170b5c0f2f7887fed04c63a385c0789f63?d=identicon)[jomonkj](/maintainers/jomonkj)

---

Top Contributors

[![jomonkj](https://avatars.githubusercontent.com/u/11212888?v=4)](https://github.com/jomonkj "jomonkj (13 commits)")

---

Tags

codextenyii2

### Embed Badge

![Health badge](/badges/codexten-yii-mailqueue/health.svg)

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

###  Alternatives

[maize-tech/laravel-email-domain-rule

Laravel Email Domain Rule

612.0k](/packages/maize-tech-laravel-email-domain-rule)[sarfraznawaz2005/noty

Laravel package to incorporate noty flash notifications into laravel.

324.5k](/packages/sarfraznawaz2005-noty)

PHPackages © 2026

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