this is a known core bug you can fix it with the following core patch.
Patch:
--- vendor/magento/framework/Mail/Template/TransportBuilder.php
+++ vendor/magento/framework/Mail/Template/TransportBuilder.php
@@ -377,6 +377,7 @@ protected function prepareMessage()
{
$template = $this->getTemplate();
$content = $template->processTemplate();
+
switch ($template->getType()) {
case TemplateTypesInterface::TYPE_TEXT:
$part['type'] = MimeInterface::TYPE_TEXT;
@@ -391,7 +392,10 @@ protected function prepareMessage()
new Phrase('Unknown template type')
);
}
+
+ /** @var \Magento\Framework\Mail\MimePartInterface $mimePart */
$mimePart = $this->mimePartInterfaceFactory->create(['content' => $content]);
+ $this->messageData['encoding'] = $mimePart->getCharset();
$this->messageData['body'] = $this->mimeMessageInterfaceFactory->create(
['parts' => [$mimePart]]
);
@@ -400,6 +404,7 @@ protected function prepareMessage()
(string)$template->getSubject(),
ENT_QUOTES
);
+
$this->message = $this->emailMessageInterfaceFactory->create($this->messageData);
return $this;
--- dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php
+++ dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php
@@ -769,7 +769,19 @@ public function testConfirmationEmailWithSpecialCharacters(): void
$message = $this->transportBuilderMock->getSentMessage();
$rawMessage = $message->getRawMessage();
- $this->assertContains('To: John Smith <' . $email . '>', $rawMessage);
+ /** @var \Zend\Mime\Part $messageBodyPart */
+ $messageBodyParts = $message->getBody()->getParts();
+ $messageBodyPart = reset($messageBodyParts);
+ $messageEncoding = $messageBodyPart->getCharset();
+ $name = 'John Smith';
+
+ if (strtoupper($messageEncoding) !== 'ASCII') {
+ $name = \Zend\Mail\Header\HeaderWrap::mimeEncodeValue($name, $messageEncoding);
+ }
+
+ $nameEmail = sprintf('%s <%s>', $name, $email);
+
+ $this->assertContains('To: ' . $nameEmail, $rawMessage);
$content = $message->getBody()->getParts()[0]->getRawContent();
$confirmationUrl = $this->getConfirmationUrlFromMessageContent($content);
--- dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php
+++ dev/tests/integration/testsuite/Magento/Customer/Controller/AccountTest.php
@@ -783,7 +783,7 @@ public function testConfirmationEmailWithSpecialCharacters(): void
$this->assertContains('To: ' . $nameEmail, $rawMessage);
- $content = $message->getBody()->getParts()[0]->getRawContent();
+ $content = $messageBodyPart->getRawContent();
$confirmationUrl = $this->getConfirmationUrlFromMessageContent($content);
$this->setRequestInfo($confirmationUrl, 'confirm');
$this->clearCookieMessagesList();
How to apply Patches on Magento 2
Isusses:
- https://github.com/magento/magento2/issues/24902
- https://github.com/magento/magento2/issues/25542
Best regards,
Lars