I use Mime mail mailer as standard plugin for formatting an email before sending it, PHPMailer SMTP as plugin for sending an email after formatting it. Email header and email body contains charset cp1251 (win1251). But email body is displayed normally, but email header is displayed as scribbles.
I tried use development version 8.x-1.x-dev, but it didn't help.
Current situation:
Mime Mail 8.x-1.0-alpha2+24-dev
PHPMailer SMTP 8.x-1.2
Drupal 8.8.2
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | Output of communication with SMTP server.txt | 7.23 KB | artyomalin |
| #8 | Test mail help.png | 37.29 KB | artyomalin |
| #3 | Settings.zip | 161.8 KB | artyomalin |
| #3 | Test mail.PNG | 33.74 KB | artyomalin |
| #3 | Configure the Mime Mail 1.PNG | 31.11 KB | artyomalin |
Comments
Comment #2
tr commentedI cannot reproduce this. I can enter non-ascii unicode characters as the subject and body, and these characters are displayed properly in the e-mail subject line and e-mail body when I receive the message. I am using Mime Mail for both the formatter and sender.
Please enable the new mimemail_example module (you will need the latest mimemail -dev for this), then go to
example/mimemail_example, fill out the form, and see if it works. If not, post the exact values you entered in that form as well as the complete source text (including headers) of the e-mail you received. Also post your mailsystem settings - either the output ofdrush cget mailsystem.settingsor the values entered atadmin/config/system/mailsystemComment #3
artyomalin commentedI did what you asked. I updated Mime Mail module to development version 8.x-1.x-dev, enabled mimemail_example and sent email message using test mimemail. But email header is displayed as scribbles.

Configure the Mail System
Test email

Screenshots with Mime mail settings and Test email settings
Screenshots with Mime mail settings and Test email settings
Comment #4
tr commentedI don't know what those first three lines of your email image are supposed to mean. Are they the the "Subject", the "From" header, the "To" header, or ... what? It doesn't help me to see the rendered email because I don't know what is being rendered - I need to see the raw text of the message. That's why I asked you to "post the exact values you entered in that form as well as the complete source text (including headers) of the e-mail you received"
This problem is not necessary from Mime Mail. It could easily be a problem with the values you entered, or it could be a problem with PHP Mailer, or it could be a problem with your email client. I told you what I did in #2 to try to reproduce the issue - now you need to tell me what I have to do differently to see the same error.
In order to help you I need to see:
1) Exactly what you entered in the mimemail_example form.
2) The RAW text of the email you received, showing all the header information and body.
3) I need to know what you expect those first three lines of your email to look like.
Comment #5
imclean commented@artyomalin, try updating PHPMailer SMTP to 1.4. There was a recent change to set a default charset, even though it isn't really the responsibility of SMTP.
How are you setting the charset? This can be set in the content type header: "Content-Type' => "text/html; charset=windows-1251"
How does MIME Mail set the charset?
Point 2 from TR in #4 is important. This is the raw source of the email. Some email clients have a menu option to view message source.
Comment #6
tr commentedThere is no such thing as a charset for message headers. Headers must be RFC 2822 encoded. Mime Mail sets the BODY Content-Type to
Content-Type: multipart/mixed; boundary="...", and the multipart/mixed content type doesn't accept a charset. Each of the text-type subparts DOES accept a charset, and Mime Mail usesutf-8for those. (Subparts like image attachments don't accept a charset either ...)So again, without seeing what was entered in the form and what was delivered in the raw e-mail, I can't draw any conclusion about where the problem lies. It could be bad RFC 2822 formatting of the headers, but there are several ways that could happen outside Mime Mail's control. In my development version I've replaced Mime Mail's custom RFC 2822 encoding function for the similar one recently added to core Drupal - I'll eventually get around to opening an issue for that and committing that change; right now I'm just using it locally to see if it causes any problems. It would be nice to have tests for all aspects of Mime Mail so we could be sure that a change like this doesn't break the 90,000 sites using Mime Mail, but for now I'm giving it the opportunity to break my sites first as a test ... But both the Mime Mail custom function and the new core function can fail when given bad input, so again I need to see what was entered on the Mime Mail Example form and I need to see how that arrived in the raw message headers.
As I said in #2, I tested this with a non-ascii Subject (specifically, with a mix of kanji characters and cyrillic characters ...) and as far as I can tell from my tests the RFC 2822 of the subject is being done correctly and the Subject is correctly displayed in my mail client. I don't know which header the OP is seeing - I had to guess that it was the Subject - so I am only guessing until I get the additional information I need to try to reproduce this.
Comment #7
imclean commentedNote: this comment is some general related information, it doesn't contain enough to solve this problem.
Strictly speaking that's true. Although unicode characters can be used by specifying the charset using the encoded-word syntax, as I see you're aware.
The PHPMailer library's default charset is iso-8859-1. Given how multilingual Drupal is that's not very useful. The Drupal module PHPMailer SMTP now defaults to UTF-8, overriding PHPMailer's default to make it more useful. This change was in response to incorrect international subject headers and resolved this issue: #3109539: Accept Special Characters (from name/ subject)
Specifying the charset in the "Content-Type" header, which it appears MIME Mail does, can override this.
The meta headers, including charset, are generally ignored by email clients but can be useful for displaying the email a web browser.
Comment #8
artyomalin commentedHello, i put prompts in Test email image for better understand where are Email header, Email sender, recipient etc.

I also enabled record debugging output in Drupal's log in "Configure the PHPMailer SMTP module" page. I again sent test email message from mimemail_example form.
This is data what i entered in the mimemail_example form:
A key to identify the email sent - test
The email address of the recipient - artem.petuhov@rsvpu.ru
The sender's name - Pedforum.rsvpu.ru
The sender's email address - ncrao@rsvpu.ru
The mail's carbon copy address (Cc) - empty
The mail's blind carbon copy address (Bcc) - empty
The address to reply to - empty
List-unsubscribe - empty
The email's subject - В вашу тему круглого стола "Новая тема" на сайте Pedforum.rsvpu.ru добавлен новый материал
HTML message -
Уважаемый руководитель темы круглого стола!
На сайте Международного научного педагогического Форума молодых исследователей (Pedforum.rsvpu.ru) в тему круглого стола "Новая тема", руководителем которой вы являетесь, добавлен новый материал.
Plain text message - empty
I wrote in file "Output of communication with SMTP server.txt" debug the full communication with the SMTP server.
Output of communication with SMTP server.txt
Comment #9
artyomalin commentedI updated PHPMailer SMTP to 1.4, but email header still has wrong charset (email sent from Test Mime Mail form).
Comment #10
tr commentedSubject: =?iso-8859-1?B?0JIg0LLQsNGI0YMg0YLQtdC80YMg0LrRgNGD0LPQu9C+0LPQviDRgdGC0L7Qu9CwICLQotC10YHRgtC+0LLQsNGPINGC0LXQvNCwIiDQvdCwINGB0LDQudGC0LUgUGVkZm9ydW0ucnN2cHUucnUg0LTQvtCx0LDQstC70LXQvSDQvdC+0LLRi9C5INC80LDRgtC10YDQuNCw0Ls=?=This is wrong. The subject should be UTF-8 encoded, and should look something like this:
This string is generated by core Drupal and "UTF-8" is hard coded into that string. I don't know what is changing that value, but it's not Mime Mail.
Content-Type: multipart/mixed; boundary="28aef08077a60789528b8c7b3e38b5639e4c8a091"; charset=iso-8859-1This is wrong, and that was not done by Mime Mail. Mime Mail sets the Content-Type header like this:
Content-Type: multipart/mixed; boundary="28aef08077a60789528b8c7b3e38b5639e4c8a091"but some other module is adding
; charset=iso-8859-1at the end. "charset" is not a valid option for the multipart/mixed type and it should NOT be there. Also, "iso-8859-1" is wrong, but again there should be nothing added to the end of that Content-Type string after the boundary.Comment #11
tr commentedI cannot help without seeing the raw HTML of the received message. I have asked for that several times now. I have tried to reproduce the problem but there are clearly some other modules involved in formatting your emails and I don't know what they are.
Closing because as far as I can tell this is working properly and I can't reproduce the problem with the information given. Feel free to open a new issue if you have the same problem and can provide the requested information.