Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.

Headers encoding problem in Zend\Mail\Message #4917

Closed
thestanislav opened this issue Jul 31, 2013 · 3 comments
Closed

Headers encoding problem in Zend\Mail\Message #4917

thestanislav opened this issue Jul 31, 2013 · 3 comments

Comments

@thestanislav
Copy link
Contributor

My mail client do not recognize mail format when I set mail Message charset to UTF-8.
Here what I got in mail headers

To: =?UTF-8?Q?=D0=A1=D1=82=D0=blahblah
Subject: =?UTF-8?Q?=D0=95=D1=81=D1=blahblah
From: =?UTF-8?Q?=D0=A0=D0=B0=D0=B4=blahblah
MIME-Version: 1.0
Content-Type: =?UTF-8?Q?text/html?=
Content-Transfer-Encoding: =?UTF-8?Q?8bit?=
Content-Disposition: =?UTF-8?Q?inline?=

According to RFC http://www.ietf.org/rfc/rfc2047.txt only specific mail headers can be encoded when charset is set to other than ASCII.

http://www.ietf.org/rfc/rfc2047.txt
....
These are the ONLY locations where an 'encoded-word' may appear. In particular:

  • An 'encoded-word' MUST NOT appear in any portion of an 'addr-spec'.
  • An 'encoded-word' MUST NOT appear within a 'quoted-string'.
  • An 'encoded-word' MUST NOT be used in a Received header field.
  • An 'encoded-word' MUST NOT be used in parameter of a MIME
    Content-Type or Content-Disposition field, or in any structured
    field body except within a 'comment' or 'phrase'.

    ....

Temporary solution can be

foreach(array('Subject', 'From', 'To') as $_h){
    $mail->getHeaders()->get($_h)->setEncoding('UTF-8');
}

$transport->send($mail);
@thestanislav
Copy link
Contributor Author

Another problem is that attached binary files with non ascii names have broken encodings.

@bhelm
Copy link

bhelm commented Jun 12, 2014

i can confirm this problem, please fix!
The temporary solution posted above works, but you have to avoid using the $mail->setEnconfig() function.

@GeeH
Copy link

GeeH commented Jun 27, 2016

This issue has been closed as part of the bug migration program as outlined here - http://framework.zend.com/blog/2016-04-11-issue-closures.html

@GeeH GeeH closed this as completed Jun 27, 2016
simon-letch pushed a commit to dotmailer/dotmailer-magento2-extension that referenced this issue Apr 16, 2019
**This is a workaround for encoding issue until Magento resolves bug**
magento/magento2#22065
magento/magento2#22103

**Change will effect Magento 2.2.8 and 2.3.+**
Because of ZF v2 usage in these versions setEncoding on message should fix encoding overall (setEncoding fixes encoding issue in subject) but because of ZF v2 bug have to fix encoding separately on body.
zendframework/zendframework#6841
zendframework/zendframework#5708
zendframework/zendframework#4917

**To test:**
- Test both email types text and html
- Test in Magento 2.3.*
- Test in Magento 2.2.8
- Test in Magento < 2.2.8
- Test using our Email Template mapped and our SMTP enabled
- Test using Magento template and our SMTP enabled
- Test using our SMTP disabled

Related work items: #86368
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants