Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of app->mail() crashes on php 8.1 #11

Open
rgvy opened this issue Dec 13, 2021 · 5 comments
Open

Use of app->mail() crashes on php 8.1 #11

rgvy opened this issue Dec 13, 2021 · 5 comments
Labels

Comments

@rgvy
Copy link

rgvy commented Dec 13, 2021

This is caused by calling the default newInstance() method. In the version of Swift Mailer used by this framework, newInstance() calls to strtolower(null) which crashes in php 8.1. In a later version of Swift Mailer, they fix this bug with strtolower(null ?? '').

@ocram ocram added the question label Dec 15, 2021
@ocram
Copy link
Contributor

ocram commented Dec 15, 2021

Thank you!

What exactly is “the version of Swift Mailer used by this framework”? This framework can actually be used with multiple versions of any dependency – unless you are referring to major versions (e.g. 1.x.x), which are often limited.

Can you go to the root folder of your project, open the CLI there and run composer show? The output should tell us exactly which version of Swift Mailer you are using.

Can you also point to the bug report or issue for Swift Mailer, or name the first version of Swift Mailer where that strtolower behavior is fixed?

@rgvy
Copy link
Author

rgvy commented Dec 15, 2021

From the composer.json in this project, it targets "^5.4". I believe that this major version is no longer supported, and Swift Mailer 6 has migrated into the Symphony project. The bug in Swift Mailer has since been fixed, but simply updating the dependency doesn't look like it will work. There appears to be a different method to construct Swift Mailer objects.

If migrating to the new Swift Mailer framework requires too many changes in the short term, there's a quick fix. Instead of calling newInstance() on line 228 of App.php, the method could call newInstance('localhost',25,'') to explicitly set that final string as an empty string instead of null. The empty string will propagate to strtolower within the Swift Mailer framework and avoid a deprecation notice exception in php 8.1.

@rgvy
Copy link
Author

rgvy commented Dec 15, 2021

You can inspect how this works by looking at the SmtpTransport.php file in the Swift Mailer project

@ocram
Copy link
Contributor

ocram commented Dec 15, 2021

Thanks!

Will use the workaround you described, at least in the very short term, unless we can include the fix via a simple update of the dependency.

In order to get the version of Swift Mailer, we really need the way I described before. Looking at composer.json is not enough, because ^5.4 is just a constraint, and, say, version 5.9.2 also fulfills that constraint. So you’d need to look either in composer.lock, or, more easily, just run composer show.

@rgvy
Copy link
Author

rgvy commented Dec 15, 2021

Ah, I understand now (sorry). Looks like composer finds version 5.4.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants