package-of-yii / mailer-gateways
Yii2 mailer component with pluggable SMTP/SparkPost/SES/Mailgun providers.
Package info
github.com/package-of-yii/yii2-mailer-gateways
Type:yii2-extension
pkg:composer/package-of-yii/mailer-gateways
v1.0.1
2026-08-07 09:09 UTC
Requires
- php: >=8.1
- pralhadstha/php-mailer-gateways: ~1.0
- yiisoft/yii2: ~2.0
- yiisoft/yii2-symfonymailer: ^3.0 || ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- phpstan/phpstan: ^1.12
- phpunit/phpunit: ^10.5
README
Yii2 mailer component with pluggable multiple mail providers including Sparkpost, SMTP, SES.
Installation
composer require package-of-yii/mailer-gateways
Then add the bridge for the provider(s) you actually use:
| Provider | Install command |
|---|---|
smtp |
(nothing extra needed) |
ses |
composer require symfony/amazon-mailer |
mailgun |
composer require symfony/mailgun-mailer |
sparkpost |
composer require gam6itko/sparkpost-mailer |
Configuration
'components' => [ 'mailer' => [ 'class' => POYii\Mail\Mailer::class, 'providerConfig' => [ 'provider' => 'sparkpost', 'api_key' => getenv('SPARKPOST_API_KEY'), ], ], ],
// SMTP 'providerConfig' => [ 'provider' => 'smtp', 'host' => 'smtp.example.com', 'port' => 587, 'username' => '...', 'password' => '...', ], // Amazon SES (mode: api [default] | https | smtp) 'providerConfig' => [ 'provider' => 'ses', 'access_key' => 'AKIA...', 'secret_key' => '...', 'region' => 'us-east-1', ], // Mailgun (mode: api [default] | https | smtp) 'providerConfig' => [ 'provider' => 'mailgun', 'key' => '...', 'domain' => 'mail.example.com', 'region' => 'eu', ], // SparkPost (mode: api [default] | smtp) 'providerConfig' => [ 'provider' => 'sparkpost', 'api_key' => '...', 'region' => 'eu', ], // Disable sending 'providerConfig' => ['provider' => 'null'], // In-memory, for tests 'providerConfig' => ['provider' => 'array'],
region is optional for ses/mailgun/sparkpost. port is optional for smtp.
Usage
Yii::$app->mailer->compose('contact/html', ['user' => $user]) ->setFrom('postmaster@example.com') ->setTo($user->email) ->setSubject('Hello') ->send();
Extending with a custom provider
$factory = new Pralhadstha\Mail\MailerFactory(); $factory->registerProvider('postmark', new App\Mail\PostmarkProvider()); 'components' => [ 'mailer' => [ 'class' => POYii\Mail\Mailer::class, 'providerConfig' => ['provider' => 'postmark', 'api_key' => '...'], 'factory' => $factory, ], ],
Development
composer install composer test composer stan composer csfix && composer cs