473,503 Members | 7,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 8708
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
2712
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
4405
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
3196
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
1606
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
2093
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
2792
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
2789
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
4675
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
4857
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
7267
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6976
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7449
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5566
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4993
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1495
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.