- Is symfony/mailer compatible with Laravel 11?
- Yes. Laravel 9 and later use Symfony Mailer internally for the Mail facade, so symfony/mailer is compatible with Laravel 10 and 11. You can use it directly for advanced transports, events, or Twig templating without replacing Laravel’s mail layer. For pre-Laravel 9 apps that still use SwiftMailer, integration requires a service provider and careful testing.
- How do I install symfony/mailer with Composer in Laravel?
- Run composer require symfony/mailer. In Laravel 9+ it is usually already present as a transitive dependency of laravel/framework, so check with composer show symfony/mailer before adding it explicitly. Add symfony/twig-bridge only if you want Symfony’s native Twig email templating.
- Can I use Blade templates with Symfony Mailer?
- Symfony Mailer’s native templating integration is Twig via TemplatedEmail and BodyRenderer, not Blade. In a Laravel app you normally keep using Mailable and Blade for templated emails, or write a custom BodyRenderer adapter that renders a Blade view into the Email HTML body. Direct Symfony Mailer use with Blade is possible but requires that adapter work.
- How do I configure symfony/mailer with an SMTP DSN?
- Create a transport with Transport::fromDsn('smtp://user:[email protected]:587') and pass it to new Mailer($transport). Store the DSN in an environment variable so you can switch between SMTP and API providers without changing send code. Then call $mailer->send($email) with a Symfony\Component\Mime\Email object.
- Which email providers does symfony/mailer support?
- Symfony Mailer supports SMTP and sendmail plus API bridges for providers such as Mailgun, Amazon SES, Mailjet, SendGrid, and Postmark. Each provider typically needs its bridge package and a matching DSN. If your provider is not covered, you can add a custom transport or fall back to SMTP.
- What PHP version is required by symfony/mailer?
- Symfony Mailer follows Symfony’s release requirements: Symfony 7.x needs PHP 8.2 or newer, and Symfony 8.x needs PHP 8.4 or newer. For older Laravel projects on legacy PHP versions, pin an older Symfony Mailer release that satisfies your composer.json constraints. Check the package requirements before upgrading.
- How do I send queued emails with symfony/mailer in Laravel?
- The simplest approach is to keep using Laravel’s Mail facade and Mail::queue(), because Laravel’s mailer already uses Symfony Mailer under the hood. If you use Symfony Mailer directly, dispatch a Laravel job that calls $mailer->send($email) inside the queue worker. Symfony’s AsyncTransport can wrap another transport, but Laravel’s queue is usually the better fit in a Laravel app.
- How do I test Symfony Mailer emails in Laravel?
- For Laravel Mailables, use Mail::fake() and assertSent as usual; Laravel’s mailer is powered by Symfony Mailer. If you call Symfony Mailer directly, inject a fake or in-memory transport and assert on the Email objects passed to send(). You can also listen for Symfony’s MessageSentEvent in tests to verify delivery events.
- What are alternatives to symfony/mailer for Laravel?
- Laravel’s built-in Mail facade is the default choice and already wraps Symfony Mailer, so it is not a separate alternative. Standalone options include PHPMailer, legacy SwiftMailer, and provider SDKs such as Mailgun or Postmark PHP clients. For most Laravel apps, Laravel Mail plus Symfony Mailer transports is the lowest-friction path.
- How do I migrate from SwiftMailer to Symfony Mailer in Laravel?
- Upgrading to Laravel 9 or later handles the framework-level SwiftMailer-to-Symfony-Mailer migration for you. Replace direct SwiftMailer code with Symfony\Component\Mime\Email objects, and move templating to Laravel Mailable/Blade or Symfony TemplatedEmail/Twig. Re-run mail tests to catch differences in headers, attachments, and events.