Email headers were designed for plain ASCII. Yet subjects such as "Réservation confirmée", names like "Zoë Müller" and entire lines in Hindi, Japanese or Arabic travel through the internet every second. The mechanism that makes this possible is the MIME encoded-word, defined in RFC 2047. When it works nobody notices. When it fails, recipients see question marks, boxes, strange sequences such as "=?UTF-8?B?" or text with accents replaced by the wrong letters. This guide explains what an encoded-word is, how to read one, which headers may contain them, what goes wrong in practice and how to test your sending code. It complements UTF-8 in email, emoji in email and email localization.
What an encoded-word looks like
Subject: =?UTF-8?B?UsOpc2VydmF0aW9uIGNvbmZpcm3DqWU=?=
From: =?UTF-8?Q?Zo=C3=AB_M=C3=BCller?= <[email protected]>
Subject: =?UTF-8?B?4KSF4KSq4KSo4KS+IOCkheCkleCkvuCkieCkguCknyDgpKjgpL/gpLDgpY3gpK4=?=Reading from left to right: the opening =?, the character set (UTF-8 is the sensible default), a question mark, the encoding letter, another question mark, the encoded text and the closing ?=. Mail clients decode these automatically for display. The two encodings are:
| Encoding | Letter | How it works | Best for |
|---|---|---|---|
| Base64 | B | The bytes of the text are Base64-encoded | Mostly non-Latin scripts (Chinese, Japanese, Arabic, Hindi) where most characters need encoding |
| Quoted-printable style | Q | Printable ASCII stays as is; other bytes become =XX; spaces become underscores | Mostly Latin text with a few accents, so the result stays somewhat readable |
The 75-character limit means a long subject is split into several encoded-words separated by folding whitespace. Each word must contain whole characters; splitting a multi-byte UTF-8 character across two encoded-words is a classic bug that produces garbled text in some clients. Correct libraries split at character boundaries.
Where encoded-words may appear
| Place | Allowed? | Notes |
|---|---|---|
| Subject | Yes | The most common case |
| Display name in From, To, Cc, Reply-To | Yes | Only in the name part, not the address. Names with special characters must also be quoted correctly |
| Comments in structured headers | Yes | Rare in practice |
| Email address (local part or domain) | No | Internationalised addresses use SMTPUTF8 or IDNA, covered below |
| Header field names | No | Names stay ASCII |
| Message-ID, Date, Received | No | Structured; ASCII only. See Date header |
| Attachment filenames | Separate mechanism | Use RFC 2231 parameter encoding or the library's support. See MIME attachments |
Why subjects and names get garbled
| Symptom | Likely cause | Fix |
|---|---|---|
| Question marks or boxes instead of letters | The text was converted to a character set that cannot hold it, or the sender used 8-bit text in the header without declaring a charset | Use UTF-8 end to end and let the library encode the header |
| Accented letters replaced by two odd characters (for example é for é) | UTF-8 bytes were interpreted as a legacy single-byte charset, or the other way around | Declare the correct charset; avoid double conversion |
| Raw =?UTF-8?B?...?= visible to the reader | The encoded-word was not recognised: missing spaces, wrong delimiters, extra quotes or an encoded-word inside a quoted string | Do not wrap encoded-words in quotes; separate adjacent words with whitespace |
| Subject cut off or characters missing in the middle | A multi-byte character was split across two encoded-words | Split on character boundaries; use a maintained library |
| Name shows with backslashes or stray quotes | Special characters such as commas or quotes were not escaped before encoding | Quote or encode the display name according to the library rules |
| Different text in different clients | A client with limited charset support or a gateway that rewrites headers | Test the same message in several clients; check gateways |
| Emoji turn into question marks | The database or code path used a 3-byte UTF-8 variant (for example MySQL utf8 instead of utf8mb4) | Store and handle text as full UTF-8. See emoji |
| Subject fine in one language, broken in another | Hard-coded charset such as ISO-8859-1 | Switch to UTF-8 everywhere |
Rules for senders
- Use a mail library that encodes headers automatically and consistently. Hand-built encoded-words are a common source of bugs.
- Choose UTF-8 as the charset for headers, text parts and HTML parts, and declare it in the Content-Type header of each part.
- Do not mix raw 8-bit text into headers. If your platform accepts a Unicode subject, make sure it encodes before sending, and that no earlier step converts the string.
- Keep subjects reasonably short. Long non-Latin subjects expand when encoded and may be truncated by clients.
- Avoid hidden or control characters, including zero-width characters, which can look like obfuscation to filters and cause display issues.
- Encode display names, not addresses. If an address itself is internationalised, use IDNA for the domain and check that the receiving side supports SMTPUTF8.
- Sign after encoding. DKIM signs the header as it will be transmitted; reencoding after signing breaks signatures. See reading authentication results.
SMTPUTF8 and internationalised addresses
RFC 6531 defines SMTPUTF8, an SMTP extension that lets headers carry raw UTF-8 and allows non-ASCII mailbox names such as 用户@例子.公司. Both sides must support it. If the next hop does not advertise SMTPUTF8 in its EHLO response, a sender cannot deliver a message that requires it, and either downgrades (where possible) or fails with an error. For ordinary marketing and transactional mail, encoded-words remain the safe, universally understood method. Use SMTPUTF8 only when you must support internationalised addresses, and test with the providers your audience uses. See SMTP extensions.
Testing
- Build a small set of test strings: Latin with accents, Cyrillic, Greek, Arabic (right-to-left), Hindi, Chinese, Japanese, Korean, emoji and a long mixed string.
- Send each as a subject and as a display name through your real sending path to accounts at several providers and clients.
- Open the received source and check the header: the charset should be UTF-8 and each encoded-word under 75 characters.
- Check the display in desktop, web and mobile clients, in list view and in notifications.
- Test replies and forwards: the quoted subject should keep its characters.
- Check logs, analytics and webhooks for the same strings, because reports often use a different path and break encoding there.
- Put the test set in your regression suite so later library updates do not reintroduce problems.
Debugging a broken subject
- Get the original message source and find the Subject header.
- Decode each encoded-word by hand or with a tool (for example Python's email.header.decode_header) and compare the result with the intended text.
- If the decoded text is already wrong, the fault is before sending: a database, form, template or API step changed the string.
- If the decoded text is right but the client shows garbage, look at the charset declaration and at gateways that rewrite headers.
- Fix the earliest wrong step, resend and verify in the same clients.
Encoded-words are old, but they are the reason a French subject, a Japanese name or a Hindi headline survives its trip across the internet. Let a good library do the encoding, keep everything in UTF-8 and test with real languages, and garbled headers become a rare surprise.
Send tested, authenticated mail Check records and headers on your sending domain.
References and further reading
Frequently asked questions
What is a MIME encoded-word?
A way to put non-ASCII text in an email header using the form =?charset?encoding?text?=, defined in RFC 2047.
What is the difference between B and Q encoding?
B uses Base64 and suits non-Latin scripts; Q keeps ASCII readable and suits Latin text with few accents.
Why does my subject show question marks?
The text was converted to a charset that cannot represent it, or was double-converted somewhere before sending.
Can I put encoded-words in the email address?
No. Encoded-words are only for text parts such as display names; internationalised addresses need IDNA or SMTPUTF8.
How do I test multilingual subjects?
Send a set of sample strings in several scripts to different clients and read the source to check UTF-8 and word lengths.