PHPackages                             laratusk/laravel-mailgun-multi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. laratusk/laravel-mailgun-multi

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

laratusk/laravel-mailgun-multi
==============================

Send emails from multiple Mailgun domains in one Laravel app — automatic transport reconfiguration based on sender domain.

v4.2.0(1mo ago)172MITPHPPHP ^8.2CI passing

Since Feb 19Pushed 2mo agoCompare

[ Source](https://github.com/laratusk/laravel-mailgun-multi)[ Packagist](https://packagist.org/packages/laratusk/laravel-mailgun-multi)[ Docs](https://github.com/laratusk/laravel-mailgun-multi)[ RSS](/packages/laratusk-laravel-mailgun-multi/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (22)Versions (5)Used By (0)

Multiple Mailgun Domains in one Laravel app
===========================================

[](#multiple-mailgun-domains-in-one-laravel-app)

[![PHP Version](https://camo.githubusercontent.com/c9f64f714c636ba27a3bba6dfd52f98426832db1262747efa54b212d16943651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c7565)](https://camo.githubusercontent.com/c9f64f714c636ba27a3bba6dfd52f98426832db1262747efa54b212d16943651/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e322d626c7565)[![Laravel](https://camo.githubusercontent.com/9bae2d9be2f5ba784143b82eae0b083e86e830cdaa9e751e8205adb30d882814/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d3130253230253743253230313125323025374325323031322d726564)](https://camo.githubusercontent.com/9bae2d9be2f5ba784143b82eae0b083e86e830cdaa9e751e8205adb30d882814/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d3130253230253743253230313125323025374325323031322d726564)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)

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
------------

[](#requirements)

- PHP &gt;= 8.2
- Laravel 10, 11, or 12

Installation
------------

[](#installation)

```
composer require laratusk/laravel-mailgun-multi
```

Laravel's auto-discovery will register the service provider automatically.

How it works
------------

[](#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
-----

[](#usage)

### Basic setup

[](#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

[](#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

[](#optional-enable-domain-switch-logging)

```
'mailgun' => [
    // ...
    'log_domain_switches' => true, // logs debug info on each transport reconfiguration
],
```

### Custom resolver

[](#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
-------

[](#testing)

```
composer test
```

Run all quality checks (format + static analysis + tests):

```
composer quality
```

Credits
-------

[](#credits)

This package is a maintained fork of [skitlabs/laravel-mailgun-multiple-domains](https://github.com/skitlabs/laravel-mailgun-multiple-domains) by [Jurre Vriezinga](https://github.com/skitlabs), which is no longer actively maintained.

Contributing
------------

[](#contributing)

Contributions are welcome. Please open an issue or pull request on [GitHub](https://github.com/laratusk/laravel-mailgun-multi).

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance86

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~11 days

Total

4

Last Release

54d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/755245aa5e4ba6c690b039cedcce5a86cd01b4f00d490cd71f03e6377ac302d5?d=identicon)[laratusk](/maintainers/laratusk)

---

Top Contributors

[![jvriezinga](https://avatars.githubusercontent.com/u/1942353?v=4)](https://github.com/jvriezinga "jvriezinga (11 commits)")[![azer1ghost](https://avatars.githubusercontent.com/u/27803185?v=4)](https://github.com/azer1ghost "azer1ghost (10 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")

---

Tags

laravelmailemailmailgunmultiple-domains

###  Code Quality

TestsPest

Static AnalysisRector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/laratusk-laravel-mailgun-multi/health.svg)

```
[![Health](https://phpackages.com/badges/laratusk-laravel-mailgun-multi/health.svg)](https://phpackages.com/packages/laratusk-laravel-mailgun-multi)
```

###  Alternatives

[propaganistas/laravel-disposable-email

Disposable email validator

5762.6M6](/packages/propaganistas-laravel-disposable-email)[coconutcraig/laravel-postmark

Laravel package for sending mail via the Postmark API

2152.9M1](/packages/coconutcraig-laravel-postmark)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
