Unicode entities in email subject

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Dear Group,

my first post to this group, so if I'm on the wrong group, my

I'm trying to send out an email in Chinese lanuage using the mail()
function in PHP.

Subject and mailbody are stored as Unicode entities (eg. 註)

The mail body renders perfectly in all tested emailclients if the mail
is sent as html.

Only the subject displays the entities but does not render the Chinese

Any ideas on how to get the mail sent with the subject displaying

Thank you in advance for any clue available on this topic.

Patrick Huss

Re: Unicode entities in email subject

Quoted text here. Click to load it

 Encoding in headers of mail messages uses a different scheme to HTML. I
believe the specification you want is RFC 1342 "Representation of Non-ASCII
Text in Internet Message Headers" (http://rfc.net/rfc1342.html )

 You'll likely have to decode the subject's HTML entity references and recode
them as above.

Andy Hassall :: andy@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

Re: Unicode entities in email subject

Quoted text here. Click to load it

The "Subject" field can be encoded as MIME header (see RFC 2045-2048).
For example, given the subject $subj encoded as a UTF-8 string,
a possible encoding might be

define("ENCODING", "UTF-8");


Note that the RFC 2047 sets a limit to the maximum lenght of the resulting
string. Beyond that limit the string must be splitted somewere.  However,
the email clients I tested are able to accept a string of any length,
so this is a problem you may ignore as a first step of the implementation.

And note that this encoding has nothing to do with the Content-Type
field or the body of the message.

Obviously, your "Unicode entities" must be converted to regular UTF-8
characters before the Base64 encoding be applied.

/_|_\  Umberto Salsi
\/_\/  www.icosaedro.it

Re: Unicode entities in email subject

Thank you very much Umberto and Andy for your help.

The script is working now and Chinese emails arrive with nice rendrered
Chinese subjects lines.

I found the following function written by ronen to convert Unicode
entities back to a unicode string:


Using this before doing the base64 encoding does the trick.

Patrick Huss

Umberto Salsi schrieb:

Quoted text here. Click to load it
Quoted text here. Click to load it

Site Timeline