laratusk/laravel-mailgun-multi
Composer 安装命令:
composer require laratusk/laravel-mailgun-multi
包简介
Send emails from multiple Mailgun domains in one Laravel app — automatic transport reconfiguration based on sender domain.
README 文档
README
Send emails from multiple Mailgun domains in a single Laravel application — automatic transport reconfiguration based on the sender's domain. No changes required in calling code.
// Without this package: calling code must select the right mailer manually Mail::mailer('mailgun-acme')->to('j.doe@example.net')->send($mailable); // With this package: just send — transport is reconfigured automatically Mail::to('j.doe@example.net')->send($mailable);
Requirements
- PHP >= 8.2
- Laravel 10, 11, 12, or 13
Installation
composer require laratusk/laravel-mailgun-multi
Laravel's auto-discovery will register the service provider automatically.
How it works
This package listens to the Illuminate\Mail\Events\MessageSending event, which Laravel dispatches just before sending each email. The listener reads the from address, extracts the sender domain, and reconfigures the Mailgun transport accordingly.
This works seamlessly for both direct and queued messages — no changes to your Mailables or controllers needed.
Usage
Basic setup
Ensure your config/services.php has a mailgun entry:
'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), 'secret' => env('MAILGUN_SECRET'), 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), ],
If your sender address is sales@acme.app, the package will automatically use mg.acme.app as the Mailgun domain.
Per-domain configuration
Add a domains key to override settings for specific sender domains:
'mailgun' => [ 'domain' => env('MAILGUN_DOMAIN'), 'secret' => env('MAILGUN_SECRET'), 'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'), 'domains' => [ 'acme.com' => [ 'domain' => 'mg.acme.com', 'secret' => 'acme-mailgun-secret', 'endpoint' => 'api.eu.mailgun.net', ], 'awesome.app' => [ // Only override the secret; domain and endpoint fall back to global defaults 'secret' => 'awesome-secret', ], ], ],
If a domain is not listed, the Mailgun domain defaults to
mg.{sender-domain}. Missingsecretorendpointvalues fall back to the global mailgun config.
Optional: enable domain switch logging
'mailgun' => [ // ... 'log_domain_switches' => true, // logs debug info on each transport reconfiguration ],
Custom resolver
If the default config-based resolution does not fit your use case, implement the MailgunSenderPropertiesResolver contract:
use Laratusk\LaravelMailgunMulti\Contracts\MailgunSenderPropertiesResolver; use Laratusk\LaravelMailgunMulti\DataObjects\MailgunSenderProperties; class MyCustomResolver implements MailgunSenderPropertiesResolver { public function resolve(string $senderDomain): MailgunSenderProperties { // Fetch config from database, cache, or any source return new MailgunSenderProperties( domain: 'mg.' . $senderDomain, secret: 'my-secret', endpoint: 'api.mailgun.net', ); } }
Then bind it in a service provider:
use Laratusk\LaravelMailgunMulti\Contracts\MailgunSenderPropertiesResolver; $this->app->bind(MailgunSenderPropertiesResolver::class, MyCustomResolver::class);
Testing
composer test
Run all quality checks (format + static analysis + tests):
composer quality
Credits
This package is a maintained fork of skitlabs/laravel-mailgun-multiple-domains by Jurre Vriezinga, which is no longer actively maintained.
Contributing
Contributions are welcome. Please open an issue or pull request on GitHub.
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 527
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-19