Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Mailer Laravel Package

symfony/mailer

Symfony Mailer is a flexible component for sending emails via SMTP and other transports. Compose rich messages with Symfony Mime, add CC/BCC and priorities, and optionally render Twig templates with TemplatedEmail and BodyRenderer.

View on GitHub
Deep Wiki
Context7

Symfony Mailer is a flexible component for sending emails in PHP via pluggable transports (e.g., SMTP/DSN). Create rich messages with the Mime API and dispatch them through a Mailer instance with minimal setup.

It also supports Twig-powered templated emails via symfony/twig-bridge, enabling clean separation of presentation and data with TemplatedEmail and a BodyRenderer.

  • Send emails via DSN-configured transports (SMTP and more)
  • Compose messages with text/HTML bodies using Email
  • Support CC, BCC, Reply-To, and priority headers
  • Integrate Twig templates and context variables for dynamic content
  • Event-driven extension points with listeners/subscribers
Frequently asked questions about Mailer
Can Symfony Mailer replace Laravel’s built-in SwiftMailer for sending emails?
Yes, Symfony Mailer can fully replace SwiftMailer in Laravel. You can bind it as a singleton in Laravel’s service provider and refactor existing Mailable classes to use Symfony’s `Email` or `TemplatedEmail` while maintaining the same API (e.g., `from()`, `to()`, `subject()`). The DSN-based configuration also aligns with Laravel’s `config/mail.php` structure.
How do I configure Symfony Mailer in Laravel to use SMTP with TLS?
Use a DSN string in Laravel’s `.env` file, like `MAIL_MAILER=smtp://user:pass@smtp.example.com?encryption=tls`. This maps directly to Symfony’s `Transport::fromDsn()` method. Alternatively, configure it in `config/mail.php` using Symfony’s `Transport` class with explicit settings for host, port, and encryption.
Does Symfony Mailer support asynchronous email sending in Laravel queues?
Yes, Symfony Mailer supports async sending via transports like `async://` or by dispatching emails to Laravel’s queue system. You can create a custom queue worker that processes emails using Symfony’s `Mailer` instance, or use the `sync://` transport with Laravel’s queue system for delayed sending.
Can I use Twig templates for emails in Laravel with Symfony Mailer?
Absolutely. Install `symfony/twig-bridge` and use `TemplatedEmail` with a `BodyRenderer` to render Twig templates. This works alongside Laravel’s Blade templates—you can migrate existing Blade emails to Twig or use both systems. The `context()` method passes dynamic data to your templates.
What Laravel versions and PHP versions does Symfony Mailer support?
Symfony Mailer works with Laravel 8+ (PHP 8.0+) and Laravel 10+ (PHP 8.2+). For PHP 8.4+, Symfony 8.x is required. Laravel 11 will support PHP 8.4+, so ensure compatibility if upgrading. Check the [Symfony documentation](https://symfony.com/doc/current/mailer.html) for version-specific details.
How do I handle email failures or retries in Symfony Mailer with Laravel?
Symfony Mailer supports retries via the `retry_period` option in DSN (e.g., `smtp://?retry_period=60`). For Laravel queues, align this with Laravel’s retry logic in `FailedJob` handlers. You can also use Symfony’s `MessageListener` to log failures or trigger custom logic before/after sending.
Are there performance differences between Symfony Mailer and SwiftMailer in Laravel?
Symfony Mailer adds minimal overhead (~5–10% per email) due to its event system, but it’s highly optimized for modern PHP. For high-volume sends (e.g., newsletters), benchmark both systems. Symfony’s transport abstraction also reduces latency by supporting async or connection-pooled transports.
Can I use Symfony Mailer with Laravel’s notifications system?
Yes, you can extend Laravel’s `Mailable` classes to use Symfony Mailer. Create a wrapper class that converts Laravel’s notification data (e.g., `MarkdownMessage`, `HtmlMessage`) into Symfony’s `Email` or `TemplatedEmail`. This requires minimal refactoring if your notifications already use a clean separation of data and presentation.
What transports does Symfony Mailer support out of the box, and how do I add custom ones?
Symfony Mailer supports 10+ transports (SMTP, SendGrid, Mailgun, AWS SES, etc.) via DSN. To add a custom transport, implement the `TransportInterface` and register it with the `TransportFactory`. Laravel’s service container can manage transport instances, making it easy to swap providers without changing business logic.
How do I test Symfony Mailer in Laravel, especially for Twig templates?
Mock the `Transport` interface to avoid real SMTP calls during tests. For Twig templates, use a `TwigEnvironment` with in-memory templates or test files. Symfony’s `Mailer` can be injected into tests via Laravel’s service container, and you can assert email content using `Email::toString()` or `TemplatedEmail::getHtmlBody()`.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport