Magento 2 : How to solve the special characters in email subject? [closed]
-
09-10-2020 - |
Question
I'm having some issues related to special characters in my transactional emails, it looks like a native bug in Magento 2.1.7 (It seems still in 2.2.3)
Steps to reproduce:
I've set the store name as "Bob's Burgers" in the admin panel, then I go to the store frontend and go to Request a password reset, in order to receive an email including the store's name that I did the setup in the admin panel.
Expected result:
The email's subject should be Reset your Bob's Burgers password as I did the setup in the admin panel.
Actual result:
The subject is Reset your Bob's Burgers password
How could I fix it?
Solution
Using this reference on the Magento 2 Repository in Github, you can create a plugin to fix like that:
di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Email\Model\Template">
<plugin name="mail_subject" type="VENDOR\MODULE\Plugin\Template" sortOrder="100" />
</type>
</config>
Template.php
namespace VENDOR\MODULE\Plugin;
class Template
{
public function afterGetSubject(
\Magento\Email\Model\Template $subject,
$result
) {
return htmlspecialchars_decode((string)$result, ENT_QUOTES);
}
}