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
Swiftmailer

Swiftmailer Laravel Package

swiftmailer/swiftmailer

Swiftmailer is a full-featured PHP library for sending email via SMTP, sendmail, or PHP mail(). It supports MIME messages, attachments, HTML/text bodies, embedded images, authentication, encryption (TLS/SSL), and extensible transports/plugins.

View on GitHub
Deep Wiki
Context7

Swiftmailer, free feature-rich PHP mailer

Frequently asked questions about Swiftmailer
Can I use swiftmailer/swiftmailer with Laravel 8 or 9?
Yes, but you may need compatibility layers like `spatie/laravel-swiftmailer` for PHP 8.x support. SwiftMailer v5.4.x works with Laravel’s Mail facade, but some features (e.g., Mailables) require manual Swift_Message composition. Test thoroughly with `php artisan mail:test`.
What’s the difference between swiftmailer/swiftmailer and symfony/mailer in Laravel?
SwiftMailer v5 is a legacy library with no active development, while `symfony/mailer` (Laravel’s default in v8+) is modern, supports async transports, and integrates natively with Mailables. Use SwiftMailer only for legacy systems or custom SMTP logic not covered by Symfony’s stack.
How do I configure SwiftMailer for SMTP with Laravel’s Mail facade?
Update `config/mail.php` to set `'driver' => 'swift'` and define SMTP settings under `'swift' => ['transport' => 'smtp', 'host' => env('MAIL_HOST'), ...]`. Then inject a `Swift_Mailer` instance via `Mail::setSwiftMailer()`. Example: `$transport = new Swift_SmtpTransport(env('MAIL_HOST'), 587); $mailer = new Swift_Mailer($transport); Mail::setSwiftMailer($mailer);`
Does swiftmailer/swiftmailer support HTML emails, attachments, and embedded images?
Yes. Use `Swift_Message` to create HTML/text parts with `setBody()`, attach files with `attach()`, and embed images via `embed()`. Example: `$message->embed(Swift_Image::fromPath('logo.png'))->setBody('...<img src="cid:logo">...');`
Is swiftmailer/swiftmailer secure for production use with TLS/SSL?
SwiftMailer v5 supports TLS/SSL for SMTP, but security patches may be delayed due to its archived status. For production, ensure PHP’s `openssl` extension is enabled and configure SMTP with `Swift_SmtpTransport::setEncryption('ssl')` or `setEncryption('tls', true)`.
How do I handle email events (e.g., logging, failed sends) with SwiftMailer?
Use SwiftMailer’s event system with `Swift_Events_EventListener`. Register a listener via `$mailer->registerPlugin(new MyEventListener())`. For Laravel, extend `Swift_Events_SimpleEventListener` and bind it to the mailer instance. Example: `Mail::getSwiftMailer()->registerPlugin(new LogFailedSends());`
Will swiftmailer/swiftmailer work with Laravel’s queue system for delayed emails?
Yes, but you’ll need to manually dispatch Swift_Message objects via Laravel’s queue system. Use `Mail::raw()` or `Mail::send()` with a custom Swift_Message, then queue the job. Note: Laravel’s Mailables won’t work natively—compose messages manually.
Are there alternatives to swiftmailer/swiftmailer for Laravel?
For modern Laravel apps, use `symfony/mailer` (default in Laravel 8+). For third-party APIs, consider Mailgun’s SDK (`mailgun/mailgun-php`) or Postmark (`postmark/php-sdk`). If you need SwiftMailer’s features, `spatie/laravel-swiftmailer` provides a compatibility layer.
How do I test email sending with SwiftMailer in Laravel?
Use Laravel’s `Mail::fake()` for unit tests or `php artisan mail:test` for SMTP validation. For SwiftMailer-specific tests, mock `Swift_Mailer` and verify messages with PHPUnit: `$this->assertCount(1, $mailer->getSentMessages());`. Test TLS/SSL connections with a local SMTP server like MailHog.
What PHP versions does swiftmailer/swiftmailer support in Laravel?
SwiftMailer v5.4.x officially supports PHP 7.2–7.4. For PHP 8.x, use `spatie/laravel-swiftmailer` or add return type declarations manually. Check compatibility with your Laravel version—Laravel 8+ may require polyfills for SwiftMailer’s older codebase.
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.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai