cspoo/swiftmailer-mailgun-bundle
Pros:
swiftmailer/swiftmailer-bundle or native PHPMailer/SwiftMailer) by adding a Mailgun HTTP transport layer..env for API keys, config/mail.php for transport defaults), reducing architectural disruption.Cons:
AppKernel), but Laravel’s SwiftMailer integration is handled differently (e.g., Mail::swap() or service providers). Requires abstraction or wrapper logic.sending), necessitating custom glue code.swiftmailer/swiftmailer-bundle (v6.x) or native SwiftMailer (v6.3+) should work, but may require:
Swift_Transport with the bundle’s MailgunTransport.MailgunTransport via Laravel’s service container (e.g., binding Swift_Transport dynamically).MAIL_DRIVER=mailgun not natively supported).api.mailgun.net → api.eu.mailgun.net for EU regions).recipient-variables for templates).php-http/guzzle5-adapter (or alternative like buzz/curl). Laravel’s built-in HTTP client (Guzzle 7+) may need adaptation.Mail::raw(), Mail::send()) assumes SMTP/other transports. Mailgun’s HTTP API requires custom handling for:
Swift_TransportException).VCR or Mockery).MAIL_DRIVER=log, MAIL_DRIVER=smtp, or dedicated packages like spatie/laravel-mailgun-driver).env() or a secrets manager?{{ user.name }}) be merged?Swift_Transport with the bundle’s MailgunTransport via a service provider:
// app/Providers/AppServiceProvider.php
public function register()
{
$this->app->bind(\Swift_Transport::class, function ($app) {
$config = $app['config']['mail.mailgun'];
return new \cspoo\Swiftmailer\MailgunTransport(
$config['key'],
$config['domain'],
new \Http\Adapter\Guzzle6Adapter(new \GuzzleHttp\Client())
);
});
}
config/mail.php:
'mailgun' => [
'key' => env('MAILGUN_KEY'),
'domain' => env('MAILGUN_DOMAIN'),
'endpoint' => env('MAILGUN_ENDPOINT', 'api.mailgun.net'),
],
spatie/laravel-mailgun-driver (if available) for tighter Laravel integration.Mail::macro() for Mailgun-specific features.composer require php-http/guzzle6-adapter
Then configure the adapter in the MailgunTransport.Mail::send()).MAIL_DRIVER=smtp configurations with the bundle.POST /messages).retry helper).message-id, queue-id).swiftmailer/swiftmailer v5.4 for Laravel 7.x).recipient-variables for templates).php-http and guzzlehttp/guzzle are installed (or alternatives like curl).composer require cspoo/swiftmailer-mailgun-bundle php-http/guzzle6-adapter
config/mail.php and .env:
MAILGUN_KEY=key-3x...
MAILGUN_DOMAIN=yourdomain.mailgun.org
401 Unauthorized).MAILGUN_KEY in .env and revoke old keys in Mailgun dashboard.How can I help you explore Laravel packages today?