magento2: Error: Class "Zend\Mail\Message" not found
Summary
This is a heads up for other developers that may run into similar issues.
- SMTP mail extension stopped working due to referencing Zend/Mail. This previously worked on v2.4.6-p3 before a routine patch application.
- Prevents mail sending
Examples
We are running on 2.4.6-p3. We recently applied a patch for an issue, and had to run composer update, however, this inadvertently broke our 3rd party Mail extension, throwing the following error:
Error: Class "Zend\Mail\Message" not found in /vendor/mageplaza/module-smtp/Mail/Transport.php:115
After debugging, this was caused by laminas/laminas-server updating from v2.16.0 to v2.17.0, which caused laminas/laminas-zendframework-bridge to be removed. This package is required by a lot of 3rd party SMTP extensions that still use Zend\Mail.
As a workaround, I have added “laminas/laminas-zendframework-bridge”: “1.8.0” as a project dependancy in composer.json.
Proposed solution
I’m not entirely sure what is best long term, should we throw deprecation notices for the use of Zend Mail?
Should Magento still require laminas-zendframework-bridge as a dependancy or lock down laminas-server to v2.16.0 until the next minor release?
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Reactions: 9
- Comments: 17 (3 by maintainers)
@engcom-November: no that’s not for Magento to deal with. It’s for end users or for 3rd party modules to do this.
I would just close this ticket. People will still be able to find this info through search engines probably.
Agreed @hostep. I was conscious of raising this as a Magento issue, but I felt it needed to be in the public domain as I can see this affecting quite a lot of people.
I have reported to mageplaza so will see what they come back with.
Good find and explanation, also good you’ve specified the simple workaround, will be helpful in case other people run into a similar problem.
However, if Magento itself doens’t reference any Zend code, it should not require
laminas/laminas-zendframework-bridgein my opinion.In your case, I think you should also report this problem to
mageplaza/module-smtpand have them look into how they can solve this problem.Hi @nghiatt01,
Thanks for this, much appreciated. I will close this ticket, and hopefully other developers and extensions providers like yourself will apply compatibility fixes.
@engcom-November Thanks for taking the information on board.
hi @nicholasfishjgm, Thanks for your contribution. We have released new version (4.7.11) to fix this issue.
Isn’t it better to introduce
laminas/laminas-zendframework-bridgeas explicit dependency instead of downgradinglaminas/laminas-server?@nicholasfishjgm I came across this issue today and solved by setting a hard dependancy in my composer.json to
"laminas/laminas-server": "2.16.0". Its definitely not a Magento issue but more on 3rd Party modules. We found Amasty and Mandril to be affected on our side so until they have caught up and resolved on their side, this fix will work.Hello @nicholasfishjgm, Thank you for the report and collaboration! Thank you @hostep, @shaughnlgh for inputs!
As mentioed here https://github.com/magento/magento2/issues/38421#issuecomment-1929292827, It would be better if
laminas/laminas-zendframework-bridgeis added as explicit dependency rather then downgrading. Hence marking this as feature request.Thank you.