#native_company# #native_desc#
#native_cta#

HTML mail and Japanese text

By Manish Prabhune
on April 28, 2003

Sending HTML mail in Japanese can be quite a task in itself
with multiple encoding schemes around.

Some problems that arise are
[a] Japanese text gets garbled
[b] Body text is ok, but subject line is garbled
[c] Mail looks ok on one of the mail clients but not on other

Since early days of double byte characters, JIS or ISO-2022-JP has
been the standard encoding for mail containing double byte characters
The below function also uses JIS as the mode of transmission to
achieve compatibility with the many mail clients.

The test will include the following mail clients
(a) Outlook Express
(b) Microsoft Outlook
(c) Netscape Mail 4.7
(d) Netscape Mail 6
(e) Becky
(f) HTML interfaces for mail like yahoo.co.jp and nifty

See the below code which is converting all the needful text to
JIS and in case of subject is also using the mb_encode_mimeheader
function to prevent the subject line getting garbled.

function send_html_mail()
{
	$to  = "[email protected]";;
	$subject = "Enter some Japanese text here";

	$message = "Enter all the Japanese "

	$s_header = "";
	$s_header = $s_header . "MIME-Version: 1.0rn";
	$s_header = $s_header . "From: [email protected]"; ;
	$s_header = $s_header . "Reply-To: [email protected]"; ;
	$s_header = $s_header . "Content-type: text/html; charset=JISrn";
	$s_header = $s_header . "Content-Transfer-Encoding:7bitrn";
	$s_header = $s_header . "Bcc: [email protected]";;

	mb_language("ja");
	$subject = mb_convert_encoding($subject, "JIS","AUTO");
	$subject = mb_encode_mimeheader($subject);

        $message = mb_convert_encoding($message, "JIS", "AUTO");

	mail($to, $subject, $message, $s_header);
}

Testing this function gave appropriate output to all of the above mail clients

MANISH PRABHUNE

imodeindia.com