{"id":22989744,"url":"https://github.com/codexten/yii-mailqueue","last_synced_at":"2026-05-18T14:41:17.173Z","repository":{"id":56955927,"uuid":"171261672","full_name":"codexten/yii-mailqueue","owner":"codexten","description":"Yii mailqueue for Yii 2.0 or higher","archived":false,"fork":false,"pushed_at":"2019-03-16T09:27:14.000Z","size":25,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-08T02:45:44.828Z","etag":null,"topics":["codexten","yii2"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/codexten.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-18T10:18:08.000Z","updated_at":"2019-03-21T17:07:01.000Z","dependencies_parsed_at":"2022-08-21T08:50:38.540Z","dependency_job_id":null,"html_url":"https://github.com/codexten/yii-mailqueue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codexten%2Fyii-mailqueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codexten%2Fyii-mailqueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codexten%2Fyii-mailqueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codexten%2Fyii-mailqueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codexten","download_url":"https://codeload.github.com/codexten/yii-mailqueue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246811248,"owners_count":20837745,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["codexten","yii2"],"created_at":"2024-12-15T04:18:27.102Z","updated_at":"2025-10-23T21:59:53.765Z","avatar_url":"https://github.com/codexten.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# yii-mailqueue\nYii mailqueue for Yii 2.0 or higher\n\nEmail queue component for yii2 that works with [yii2-swiftmailer](http://www.yiiframework.com/doc-2.0/ext-swiftmailer-index.html)\n\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](http://getcomposer.org/download/).\n\nEither run\n\n```\nphp composer.phar require --prefer-dist nterms/yii2-mailqueue \"*\"\n```\n\nor add\n\n```\n\"nterms/yii2-mailqueue\": \"*\"\n```\n\nto the require section of your `composer.json` file.\n\n \nConfiguration\n-------------\nOnce the extension is installed, add following code to your application configuration :\n\n```php\nreturn [\n    //....\n    'components' =\u003e [\n        'mailqueue' =\u003e [\n            'class' =\u003e 'nterms\\mailqueue\\MailQueue',\n\t\t\t'table' =\u003e '{{%mail_queue}}',\n\t\t\t'mailsPerRound' =\u003e 10,\n\t\t\t'maxAttempts' =\u003e 3,\n        ],\n    ],\n];\n```\n\nFollowing properties are available for customizing the mail queue behavior.\n\n- `table`: Name of the database table to store emails added to the queue.\n- `mailsPerRound`: Number of emails to send at a time.\n- `maxAttempts`: Maximum number of sending attempts per email.\n\n\nUpdating database schema\n------------------------\n\nApply the database migration to create the table required to store the mail queue messages. To do this, \nadd following code to `/config/console.php`:\n\n```php\nreturn [\n    //....\n    'components' =\u003e [\n        'mailqueue' =\u003e [\n            'class' =\u003e 'nterms\\mailqueue\\MailQueue',\n\t\t\t'table' =\u003e '{{%mail_queue}}',\n        ],\n    ],\n];\n```\n\nthen run `yii migrate` command in command line:\n\n```\nphp yii migrate/up --migrationPath=@vendor/nterms/yii2-mailqueue/migrations/\n```\n\nProcessing the mail queue\n-------------------------\n\nNow calling `process()` on `Yii::$app-\u003emailqueue` will process the message queue and send out the emails. \nIn one of your controller actions:\n\n```php\n\npublic function actionSend()\n{\n\tYii::$app-\u003emailqueue-\u003eprocess();\n}\n\n```\n\nMost preferably this could be a console command (eg: mail/send) which can be triggered by a CRON job.\n\n\nSetting the CRON job\n--------------------\n\nSet a CRON job to run console command:\n\n```\n\n*/10 * * * * php /var/www/html/myapp/yii mailqueue/process\n\n```\n\n\nUsage\n-----\n\nYou can then send an email to the queue as follows:\n\n```php\nYii::$app-\u003emailqueue-\u003ecompose('contact/html')\n     -\u003esetFrom('from@domain.com')\n     -\u003esetTo($form-\u003eemail)\n     -\u003esetSubject($form-\u003esubject)\n     -\u003esetTextBody($form-\u003ebody)\n     -\u003equeue();\n```\n\nWhile `nterms\\mailqueue\\MailQueue` extends from `yii\\swiftmailer\\Mailer`, you can replace it with this extension by adding \n`yii2-swiftmailer` configuations directly to `mailqueue` configurations as follows:\n\n```php\nreturn [\n    //....\n    'components' =\u003e [\n        'mailqueue' =\u003e [\n            'class' =\u003e 'nterms\\mailqueue\\MailQueue',\n\t\t\t'table' =\u003e '{{%mail_queue}}',\n\t\t\t'mailsPerRound' =\u003e 10,\n\t\t\t'maxAttempts' =\u003e 3,\n\t\t\t'transport' =\u003e [\n\t\t\t\t'class' =\u003e 'Swift_SmtpTransport',\n\t\t\t\t'host' =\u003e 'localhost',\n\t\t\t\t'username' =\u003e 'username',\n\t\t\t\t'password' =\u003e 'password',\n\t\t\t\t'port' =\u003e '587',\n\t\t\t\t'encryption' =\u003e 'tls',\n\t\t\t],\n        ],\n    ],\n];\n```\n\nAnd use following code for directly sending emails as you ususally do with `yii2-swiftmailer`:\n\n```php\nYii::$app-\u003emailqueue-\u003ecompose('contact/html')\n     -\u003esetFrom('from@domain.com')\n     -\u003esetTo($form-\u003eemail)\n     -\u003esetSubject($form-\u003esubject)\n     -\u003esetTextBody($form-\u003ebody)\n     -\u003esend();\n```\n\nLicense\n-------\n\n[MIT](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodexten%2Fyii-mailqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodexten%2Fyii-mailqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodexten%2Fyii-mailqueue/lists"}