package-of-yii/mailer-gateways

Yii2 mailer component with pluggable SMTP/SparkPost/SES/Mailgun providers.

Maintainers

Package info

github.com/package-of-yii/yii2-mailer-gateways

Type:yii2-extension

pkg:composer/package-of-yii/mailer-gateways

Transparency log

Statistics

Installs: 5

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.1 2026-08-07 09:09 UTC

This package is auto-updated.

Last update: 2026-08-07 12:15:59 UTC


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