1

I am showing these errors in my system log while requesting a password reset, and the customer don't receive the email.

[2020-01-09 05:16:28] main.CRITICAL: Exception message: Invalid header value detected
Trace: <pre>#1 Zend\Mail\Header\AbstractAddressList->getFieldValue(true) called at [vendor/zendframework/zend-mail/src/Header/AbstractAddressList.php:209]
#2 Zend\Mail\Header\AbstractAddressList->toString() called at [vendor/zendframework/zend-mail/src/Headers.php:426]
#3 Zend\Mail\Headers->toString() called at [vendor/zendframework/zend-mail/src/Message.php:546]
#4 Zend\Mail\Message->toString() called at [vendor/magento/framework/Mail/EmailMessage.php:217]
#5 Magento\Framework\Mail\EmailMessage->toString() called at [vendor/magento/framework/Mail/EmailMessage.php:209]
5

This is a bug of Magento version 2.3.3. It does not allow the use of special characters such as ã, ơ in-store email address or sender mail name or etc...

This is a changed path in Magento

vendor/magento/framework/Mail/EmailMessage.php

Please replace function with this code in above file :

public function toString(): string {
    $this->message->setEncoding('utf-8');
    return $this->message->toString();
}
| improve this answer | |
2

Yes, it is a bug with encoding ...

In the EmailMessage class (vendor/magento/framework/Mail/EmailMessage.php) the encoding can be set if passed in an argument in the constructor, but it is null by default.

if ($encoding) {
   $this->message->setEncoding($encoding);
}

So, I think the best practice use type in di.xml in your module without rewrite and plugins

<type name="Magento\Framework\Mail\EmailMessage">
   <arguments>
       <argument name="encoding" xsi:type="string">utf-8</argument>
   </arguments>
</type>
| improve this answer | |
0

Here is the class in case some one wonders what is going on:

class SenderBuilder extends \Magento\Sales\Model\Order\Email\SenderBuilder
{
    /**
     * @throws \Magento\Framework\Exception\LocalizedException
     * @throws \Magento\Framework\Exception\MailException
     */
    public function send()
    {
        $this->configureEmailTemplate();
        //Removed Customer name because of diacritics
        $this->transportBuilder->addTo(
            $this->identityContainer->getCustomerEmail()
        );

        $copyTo = $this->identityContainer->getEmailCopyTo();
        if (!empty($copyTo) && $this->identityContainer->getCopyMethod() == 'bcc') {
            foreach ($copyTo as $email) {
                $this->transportBuilder->addBcc($email);
            }
        }

        $transport = $this->transportBuilder->getTransport();
        $transport->sendMessage();
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.