473,327 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Unicode entities in email subject

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
3 8693
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: aurora | last post by:
I have long find the Python default encoding of strict ASCII frustrating. For one thing I prefer to get garbage character than an exception. But the biggest issue is Unicode exception often pop up...
5
by: Nancy | last post by:
I recently completed a web page, "Browser Tests of Entities in 2004". http://www.santagata.us/characters/CharacterEntities.html It shows those characters that work in all of the version 5.2+...
1
by: Mark Johnson | last post by:
I wonder if anyone has a solution? I wanted to use the web browser control as a 'zoom' box for a smaller textbox. I can format in the control, and save whatever formatting as HTML code back to the...
3
by: Robin Haswell | last post by:
Hey guys I'm currently screenscraping some Swedish site, and i need a method to convert XML entities (&amp; etc, plus d etc) to Unicode characters. I'm sure one of python's myriad of XML processors...
1
by: zunbeltz | last post by:
Hi, I'm parsing html. I have a page with a lot of html enitties for hebrew characters. When i print what i get are blanks, dots and commas. How can i decode this entities to unicode charachters?...
8
by: lorenzo.viscanti | last post by:
X-No-Archive: yes Hi, I've found lots of material on the net about unicode html conversions, but still i'm having many problems converting unicode characters to html entities. Is there any...
2
by: Frantic | last post by:
I'm working on a list of japaneese entities that contain the entity, the unicode hexadecimal code and the xml/sgml entity used for that entity. A unicode document is read into the program, then the...
6
by: Clodoaldo | last post by:
I was looking for a function to transform a unicode string into htmlentities. Not only the usual html escaping thing but all characters. As I didn't find I wrote my own: # -*- coding: utf-8...
2
by: neovantage | last post by:
hey geeks, I am using a function which convert unicode to entities. So that i can save values into mysql database into entities. This function really helps me when i display the store entity data...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.