承接 laratusk/laravel-mailgun-multi 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

PHP Version Laravel License

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}. Missing secret or endpoint values 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

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-19

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固