ashraful19 / laravel-mailbridge
Provider-neutral transactional and marketing email bridge for Laravel.
Requires
- php: ^8.2
- illuminate/console: ^12.0|^13.0
- illuminate/contracts: ^12.0|^13.0
- illuminate/mail: ^12.0|^13.0
- illuminate/process: ^12.0|^13.0
- illuminate/support: ^12.0|^13.0
Requires (Dev)
- aws/aws-sdk-php: 3.379.0
- convertkit/convertkitapi: 2.4
- getbrevo/brevo-php: 2.0.14
- mailchimp/marketing: 3.0.80
- mailchimp/transactional: 1.4.1
- mailerlite/mailerlite-php: 1.0.5
- mailersend/laravel-driver: 3.1.0
- mailgun/mailgun-php: 4.4.0
- mailjet/mailjet-apiv3-php: 1.6.6
- nyholm/psr7: 1.8.2
- orchestra/testbench: ^10.0|^11.0
- phpunit/phpunit: ^11.0|^12.0
- resend/resend-php: 1.1.0
- sendgrid/sendgrid: 8.1.11
- symfony/http-client: 7.4.8
- wildbit/postmark-php: 7.0.0
Suggests
- aws/aws-sdk-php: Install with `php artisan mailbridge:install ses` for Amazon SES support.
- convertkit/convertkitapi: Install with `php artisan mailbridge:install kit` for Kit support.
- getbrevo/brevo-php: Install with `php artisan mailbridge:install brevo` for Brevo support.
- mailchimp/marketing: Install with `php artisan mailbridge:install mailchimp` for Mailchimp Marketing support.
- mailchimp/transactional: Install with `php artisan mailbridge:install mailchimp` for Mailchimp Transactional support.
- mailerlite/mailerlite-php: Install with `php artisan mailbridge:install mailerlite` for MailerLite support.
- mailersend/laravel-driver: Install with `php artisan mailbridge:install mailersend` for MailerSend support.
- mailgun/mailgun-php: Install with `php artisan mailbridge:install mailgun` for Mailgun support.
- mailjet/mailjet-apiv3-php: Install with `php artisan mailbridge:install mailjet` for Mailjet support.
- resend/resend-php: Install with `php artisan mailbridge:install resend` for Resend support.
- sendgrid/sendgrid: Install with `php artisan mailbridge:install sendgrid` for SendGrid support.
- wildbit/postmark-php: Install with `php artisan mailbridge:install postmark` for Postmark support.
README
Provider-neutral transactional and marketing email for Laravel 12+.
MailBridge keeps your application code stable while providers, SDKs, template ids, and marketing APIs vary behind adapters. Your app uses the same MailBridge methods while SendGrid, Amazon SES, Brevo, MailerSend, Resend, Postmark, Mailchimp, Kit, MailerLite, Mailgun, and Mailjet each run through their official SDKs internally.
Documentation
Full docs: https://ashraful19.github.io/laravel-mailbridge/
Source docs:
- Installation
- Provider install
- Laravel mail compatibility
- Transactional email
- Hosted templates and provider-specific data
- Marketing email
- Response shapes
- Fallback
- Testing
- Security
- Capabilities
- Troubleshooting
Quick Start
composer require ashraful19/laravel-mailbridge php artisan vendor:publish --tag=mailbridge-config php artisan mailbridge:install
mailbridge:install opens a terminal checklist so you can install one or more provider SDKs. The base package does not install every SDK.
Set the env vars for the providers you use:
MAIL_FROM_ADDRESS=hello@example.com MAIL_FROM_NAME="Example App" MAILBRIDGE_TRANSACTIONAL=brevo MAILBRIDGE_MARKETING=mailerlite BREVO_API_KEY= SENDGRID_API_KEY= SENDGRID_MARKETING_SENDER_ID= AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= AWS_DEFAULT_REGION=us-east-1 MAILERLITE_API_KEY= MAILCHIMP_API_KEY= MAILCHIMP_SERVER_PREFIX=us1 MAILCHIMP_AUDIENCE_ID= MAILCHIMP_TRANSACTIONAL_API_KEY= KIT_API_KEY= MAILJET_API_KEY= MAILJET_SECRET_KEY=
Basic Usage
Existing Laravel mail stays compatible:
Mail::to($user)->send(new WelcomeMail($user));
Send a Laravel Mailable through MailBridge:
MailBridge::transactional() ->to($user->email, $user->name) ->send(new WelcomeMail($user));
Send a provider-hosted template:
MailBridge::transactional() ->template('welcome') ->to($user->email) ->data(['name' => $user->name]) ->send();
Use provider-specific template data when providers expect different variable names:
MailBridge::transactional() ->template('welcome') ->to($user->email) ->data(['name' => $user->name]) ->dataFor('brevo', ['FIRSTNAME' => $user->name]) ->dataFor('postmark', ['name' => $user->name]) ->send();
Send through one provider for this request:
MailBridge::transactional('postmark') ->withFallback(false) ->to($user->email) ->subject('Welcome') ->text('Hello') ->send();
Subscribe a marketing contact:
use Ashraful19\LaravelMailbridge\Data\Subscriber; MailBridge::marketing() ->list('signup') ->subscribe(Subscriber::make($user->email)->name($user->name));
Work with subscribers and campaigns using the same API across marketing providers:
use Ashraful19\LaravelMailbridge\Data\Campaign; MailBridge::marketing() ->list('signup') ->unsubscribe($user->email); $subscriber = MailBridge::marketing()->getSubscriber($user->email); $campaign = MailBridge::marketing() ->createCampaign( Campaign::make('Product Launch') ->subject('New release is live') ->html('<h1>Launch</h1>') ->list('signup') );
Return Objects
Transactional send returns SendResult:
$result = MailBridge::transactional() ->to($user->email) ->subject('Welcome') ->text('Hello') ->send(); $result->provider; // string, selected provider name $result->messageId; // ?string, provider message id when available $result->metadata; // array, provider-specific extra data
Marketing actions return MarketingResult:
$result = MailBridge::marketing() ->list('signup') ->subscribe(Subscriber::make($user->email)); $result->provider; // string $result->operation; // string, e.g. subscribe, campaign_create $result->metadata; // array, provider-specific fields
Subscriber lookup returns SubscriberRecord|null:
$record = MailBridge::marketing()->getSubscriber($user->email); // null when subscriber not found $record?->provider; // string $record?->email; // string $record?->data; // array, provider-native payload
Providers
Provider SDKs are installed only when selected, and each install command uses the exact SDK version tested by MailBridge.
| Provider | Lane | Current adapter support | Install |
|---|---|---|---|
| SendGrid | Transactional + marketing | raw send, hosted templates, categories, custom args, contacts, lists, campaigns | php artisan mailbridge:install sendgrid |
| Amazon SES | Transactional | raw send, hosted templates, SES tags, raw MIME attachments | php artisan mailbridge:install ses |
| Brevo | Transactional + marketing | raw send, hosted templates, tags, subscribers, campaigns | php artisan mailbridge:install brevo |
| MailerSend | Transactional | raw send, hosted templates, personalization, tags | php artisan mailbridge:install mailersend |
| Resend | Transactional | raw send, template payload, tags/headers | php artisan mailbridge:install resend |
| Postmark | Transactional | raw send, hosted templates, tags, metadata, message streams | php artisan mailbridge:install postmark |
| Mailchimp | Transactional + marketing | Mailchimp Transactional sends, audiences, subscribers, tags, campaigns | php artisan mailbridge:install mailchimp |
| Kit | Marketing | subscribers, tags/forms/sequences, broadcasts | php artisan mailbridge:install kit |
| MailerLite | Marketing | subscribers, groups, fields, campaigns | php artisan mailbridge:install mailerlite |
| Mailgun | Transactional | raw send, hosted templates, tags, variables, metadata | php artisan mailbridge:install mailgun |
| Mailjet | Transactional + marketing | raw send, hosted templates, subscribers, lists, campaigns | php artisan mailbridge:install mailjet |
Run health checks anytime:
php artisan mailbridge:doctor
Features
Transactional email:
| Feature | Purpose |
|---|---|
| Raw HTML/text send | Send simple app-rendered messages without a Laravel Mailable. |
Laravel Mailable send |
Keep existing Laravel mail classes and route them through MailBridge. |
| Provider-hosted templates | Send by config alias with template('welcome') or direct id with templateId(...). |
| Provider-specific template data | Use data() for common variables and dataFor() for provider overrides. |
| Recipients | Normalize to, cc, bcc, from, and replyTo across providers. |
| Attachments | Add files or raw data with attach() and attachData(). |
| Tags/categories | Attach provider analytics tags where supported. |
| Metadata/custom args | Attach safe message metadata for provider analytics and webhook correlation. |
| Provider override | Send one message through a specific provider without changing config. |
| Fallback control | Use withFallback() or withFallback(false) per send. |
| Testing fake | Assert transactional sends without touching provider APIs. |
Provider note: SendGrid, Brevo, and Mailjet marketing list IDs must be numeric. MailBridge validates these IDs before building provider payloads.
Marketing email currently implemented in the common API:
| Feature | Purpose |
|---|---|
| Subscriber subscribe | Create or update contacts where the provider endpoint supports it. |
| Subscriber unsubscribe | Remove a contact from a list or group. |
| Subscriber lookup/delete | Read or delete a marketing contact. |
| List/group subscribe | Subscribe contacts to configured list aliases. |
| Fields/attributes | Sync custom subscriber profile data. |
| Campaigns | Create, send, schedule, get, and delete campaign records where supported. |
| Provider override | Run one marketing operation through a specific provider. |
| Fallback control | Retry transient provider/network failures through configured fallbacks. |
| Testing fake | Assert marketing subscriptions without provider calls. |
Why MailBridge
| Need | MailBridge behavior |
|---|---|
Keep Laravel Mailable classes |
Mail::send() still works; MailBridge can also send Mailable objects. |
| Avoid installing every SDK | Provider SDKs are optional and installed per provider. |
| Prevent surprise SDK breaks | Install commands use tested exact versions. |
| Use hosted templates | Send by template('welcome') alias or direct templateId('...'). |
| Switch provider per send | Pass provider name: MailBridge::transactional('postmark'). |
| Control fallback | Use withFallback() or withFallback(false) per send. |
| Test safely | Use MailBridge::fake() and assertions. |
License
Laravel MailBridge is open-sourced software licensed under the MIT license.