magento2: M2.3.3 breaks email sending when name contains non-ASCII char

Preconditions (*)

  1. Magento M2.3.3

Steps to reproduce (*)

  1. Open registration or contact us page
  2. Enter correct details and as a name include some non-ASCII char, i.e some õäöü

Expected result (*)

  1. After registration user receives email
  2. No errors exist in var/log/exception.log

Actual result (*)

  1. User doesn’t receive email
  2. Log includes Exception with message Invalid header value detected
[2019-10-07 11:33:57] report.CRITICAL: Invalid header value detected {"exception":"[object] (Magento\\Framework\\Exception\\MailException(code: 0): Invalid header value detected at vendor/magento/module-email/Model/Transport.php:104, Zend\\Mail\\Header\\Exception\\RuntimeException(code: 0): Invalid header value detected at vendor/zendframework/zend-mail/src/Header/HeaderValue.php:112)"}

Reasons:

Potential fix is to add encoding in vendor/magento/framework/Mail/Template/TransportBuilder.php

--- vendor/magento/framework/Mail/Template/TransportBuilder.php.org	2019-10-07 17:16:16.946791204 +0200
+++ vendor/magento/framework/Mail/Template/TransportBuilder.php	2019-10-07 17:16:44.243320666 +0200
@@ -402,6 +402,7 @@
             (string)$template->getSubject(),
             ENT_QUOTES
         );
+        $this->messageData['encoding'] = $mimePart->getCharset();
         $this->message = $this->emailMessageInterfaceFactory->create($this->messageData);

         return $this;

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 17 (11 by maintainers)

Most upvoted comments

I am on Magento 2.3.3 and I still have this issue.

We’ve worked around this on Magento 2.3.4 with the following composer patch on magento\framework

diff --git a/Framework/Mail/Address.php b/Framework/Mail/Address.php
index 18e1a8c72f2..7bf55e9fd3f 100644
--- a/Framework/Mail/Address.php
+++ b/Framework/Mail/Address.php
@@ -32,6 +32,11 @@ class Address
         ?string $email,
         ?string $name
     ) {
+        
+        if (is_string($name) && $name != '') {
+            $name = iconv('UTF-8', 'ASCII//TRANSLIT', $name);
+        }
+
         $this->email = $email;
         $this->name = $name;
     }