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
Yii2 Swiftmailer

Yii2 Swiftmailer Laravel Package

yiisoft/yii2-swiftmailer

SwiftMailer integration for Yii2 apps. Send emails via SMTP, sendmail or third-party transports with simple configuration, templated messages, and Yii2 mailer component support for composing and delivering HTML/text mail reliably across environments.

Deep Wiki
Context7

yiisoft/yii2-swiftmailer integrates the SwiftMailer library into the Yii2 framework, providing a clean mailer component for composing and sending emails from your application. It offers a familiar Yii configuration experience while supporting common transport options for reliable delivery across environments.

Use it to send transactional emails, notifications, and templated messages with minimal setup, leveraging SwiftMailer’s capabilities through Yii’s mail abstractions.

  • Seamless Yii2 Mailer component integration and configuration
  • Multiple transports: SMTP, sendmail, and more
  • Compose messages with HTML/text bodies, attachments, and embedded images
  • Supports views/templates for reusable email layouts
  • Flexible settings per environment (dev/staging/prod)
Frequently asked questions about Yii2 Swiftmailer
How do I install yiisoft/yii2-swiftmailer in a Yii2 project?
Run `composer require yiisoft/yii2-swiftmailer` to install the package. Then configure the mailer component in your Yii2 config file (e.g., `config/web.php`) under the `components` array. The package integrates directly with Yii2’s DI container, so no additional setup is needed beyond SwiftMailer’s transport configuration.
Does this package support SMTP authentication and TLS/SSL?
Yes, the package supports SMTP authentication and encryption. Configure the `transport` key in your Yii2 mailer component with `class` set to `Swift_SmtpTransport`, then specify `host`, `username`, `password`, `port`, and `encryption` (e.g., `tls` or `ssl`). Example: `'encryption' => 'tls', 'port' => 587`.
Can I use HTML templates for emails with this package?
Yes, you can compose emails with HTML and text bodies using Yii2’s view rendering. Pass a view file path to the `render()` method of the mailer component, or manually set HTML content via `setHtmlBody()`. The package supports attachments and embedded images alongside templated content.
What Laravel versions or frameworks is this package compatible with?
This package is **not** designed for Laravel—it’s built for **Yii2** (a separate PHP framework). If you’re using Laravel, use its built-in `Illuminate/Mail` or Symfony Mailer instead. For Yii2, it works with versions up to Yii2’s last major release (2023), but may require PHP 8.x compatibility fixes.
How do I test email sending without actually sending emails?
Enable file transport in your Yii2 config by setting `'useFileTransport' => true` in the mailer component. Emails will be saved to a directory (default: `runtime/mail/`), allowing you to verify content without sending. Disable this in production by setting it to `false`.
Is this package actively maintained? What about SwiftMailer’s deprecation?
The package has **no active maintenance** and relies on SwiftMailer, which is deprecated in favor of Symfony Mailer. If SwiftMailer’s deprecation causes issues, you’ll need to migrate to a modern alternative like Symfony Mailer or Laravel’s mail system. Consider this a legacy solution for Yii2 projects only.
Can I use third-party email services like SendGrid or Mailgun with this package?
Yes, but you’ll need to configure a custom transport. For example, use `Swift_SendmailTransport` for sendmail or create a custom transport class extending `Swift_Transport` to integrate with SendGrid/Mailgun APIs. The package supports any SwiftMailer-compatible transport, but modern API integrations may require additional coding.
How do I handle email attachments or embedded images in Yii2 with this package?
Attach files using the `attach()` method on the SwiftMailer message object (e.g., `$message->attach($filePath)`). For embedded images, use `embed()` and reference the CID in your HTML email. Example: `$message->embed(Yii::getAlias('@app/web/images/logo.png'))->setBody('<img src="cid:logo">', 'text/html')`.
Will this package work with PHP 8.x, or do I need compatibility fixes?
The last release (2018) likely targets PHP 7.1–7.3. For PHP 8.x, you may encounter issues with named arguments or type declarations. Check for community patches or consider forking the package to add PHP 8 support, though this is not officially maintained.
What are the alternatives to yiisoft/yii2-swiftmailer for Yii2 or Laravel?
For **Yii2**, no modern alternatives exist—this package is the de facto choice despite SwiftMailer’s deprecation. For **Laravel**, use `Illuminate/Mail` (built-in) or `symfony/mailer` (for Symfony Mailer integration). If migrating from Yii2 to Laravel, rewrite email logic using Laravel’s mail system or create a custom adapter layer.
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