DEV Community

Andrej Rypo
Andrej Rypo

Posted on

Swiftmailer on PHP 8.2

One of the essential requirements for software to be maintained is the ability to upgrade the internals, hardware, operating system etc. to the latest possible versions. Long-term.

Lately, I've been working on a few legacy apps that needed new life breathed into them. Some ran 7.4, some even older versions of PHP.

One of external dependencies that these apps had in common was now long abandoned Swiftmailer by Symfony.

The original Swiftmailer runs on PHP versions up to 8.1, and no later. PHP 8.1 will be end-of-life by the end of 2024.

For some reason I've had trouble finding a fork that would reliably support PHP 8.2.

Without further ado, here is a Swiftmailer fork that can be run without any deprecation warnings on PHP 8.2:

GitHub logo viaaurea / swiftmailer-legacy

Comprehensive mailing tools for PHP with recent PHP support

Swift Mailer Legacy

This is a fork of legacy swiftmailer/swiftmailer updated to run on PHP 8.2 and possibly future versions without any deprecation warnings or compatibility issues, maintained by Via Aurea.


composer require viaaurea/swiftmailer-legacy -W

Legacy port development notes here.

Swift Mailer

The original Swiftmailer stopped being maintained at the end of November 2021.

Please, move to Symfony Mailer at your earliest convenience. Symfony Mailer is the next evolution of Swiftmailer. It provides the same features with support for modern PHP code and support for third-party providers.

Swift Mailer is a component based mailing solution for PHP. It is released under the MIT license.

Swift Mailer is highly object-oriented by design and lends itself to use in complex web application with a great deal of flexibility.

For full details on usage, read the documentation.

All anyone willing to upgrade to PHP 8.2 has to do is type

composer require viaaurea/swiftmailer-legacy -W
Enter fullscreen mode Exit fullscreen mode

This will replace the original package without breaking requirements by other packages that rely on Swiftmailer being installed.

The fork is a fully compatible drop-in replacement of the original Swiftmailer with minimal code changes to support PHP 8.2.

Top comments (2)

xwero profile image
david duymelinck

I checked the dependents on packagist and most of them are abandoned.

So my question is why would you keep using swiftmailer?
Another question I have is are the packages that depend on swiftmailer PHP 8.2 compatible?

I think it would be better to update the packages to ones that are actively maintaned.

As a coding exercise updating an abandoned package is a great way to learn more about the new language features and use them in a real world situation.

dakujem profile image
Andrej Rypo

I can only agree.
By all means, upgrade to other mailers ASAP. Symfony mailer works great for us.

This legacy port package is intended solely for those attempting incremental upgrades of legacy code bases. There are projects where Swiftmailer would block such an upgrade and while being used for a feature or two, mailing might not be the core of the project's business. As such, replacing it with new tech might get the least priority. With a monolith design it's hard to decouple such parts and the project has to be migrated as a whole. This is where this legacy port comes handy.

The dependencies come from the original Swiftmailer and work with PHP 8.2, as far as I can tell. We do not intend to alter the codebase heavily, because there is no point in doing so. That's why it's unlikely the dependencies will be changed. However, quality PRs would be welcome.

As for the dependents, there still are many projects using swiftmailer. Many would not even use Composer, as Swiftmailer predates Composer.