By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,483 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,483 IT Pros & Developers. It's quick & easy.

Unicode entities in email subject

P: n/a
Dear Group,

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

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
chars.

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

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

Patrick Huss

Dec 8 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 8 Dec 2006 07:29:39 -0800, "Laangen_LU" <pa**********@gmail.comwrote:
>my first post to this group, so if I'm on the wrong group, my
apologies.

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
chars.

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

Thank you in advance for any clue available on this topic.
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 :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Dec 8 '06 #2

P: n/a
"Laangen_LU" <pa**********@gmail.comwrote:
my first post to this group, so if I'm on the wrong group, my
apologies.

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
chars.

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

Thank you in advance for any clue available on this topic.
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");

$header = "Subject: =?" . ENCODING . "?B?" . base64_encode($subj) . "?=\r\n";

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.

Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it

Dec 8 '06 #3

P: n/a
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:

http://www.zend.com/codex.php?id=838&single=1

Using this before doing the base64 encoding does the trick.

Cheers,
Patrick Huss
Umberto Salsi schrieb:
"Laangen_LU" <pa**********@gmail.comwrote:
my first post to this group, so if I'm on the wrong group, my
apologies.

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
chars.

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

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

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");

$header = "Subject: =?" . ENCODING . "?B?" . base64_encode($subj) . "?=\r\n";

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.

Regards,
___
/_|_\ Umberto Salsi
\/_\/ www.icosaedro.it
Dec 11 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.