Home
TeamSite
UTF-8 character issue in sendmail
jk8
We are using the following header code to create an HTML email with utf-8 characters:
my $mailer = new Mail::Mailer('sendmail');
my(%headers) = ('To' => $to_users,
'Cc' => $cc_users,
'From' => $from_user,
'Subject' => $email_subject,
'Date' => $date,
'MIME-Version' => "1.0",
'CONTENT-TYPE' => "text/html; charset=utf-8",
);
This doesn't seem to display the utf-8 characters correctly. It displays some of the German utf-8 characters correctly. But all the Japanese utf-8 characters are not displayed correctly.
Any idea on how to display utf-8 characters in an HTML email using sendmail.
-Thanks
JK
Find more posts tagged with
Comments
rollo
This should probably be in the bit-bucket forum, but you might try changing the Content-Type header to:
Content-Type: text/html; charset=Shift_JIS
or
Content-Type: text/html; charset=EUC-JP
depending of course on which encoding method you are using.
jk8
I tried both the charsets you recommended and it did not work.
rollo
There must be some other problem with it then, because those are the correct character set definitions.
Here's an dump of what I sent to the SMTP server (this may or may not look okay in your browser, but it's worth a try). Bear in mind that the headers are on the minimal side for simplicity's sake:
For Shift_JIS encoding:
From:
email@domain.com
To:
email@domain.com
MIME-Version: 1.0
Content-Type: text/html; charset=Shift_JIS
Date: Fri, 25 Apr 2003 08:53:14 -0800 (PST)
Subject: Test
<html>
<head></head>
<body>
‚·‚łɓd˜b‰ñ�ü‚ª‚¨‹q—l‚Ì‘î“à‚ÉŽ{�Ý‚³‚ê‚Ä‚¢‚é�ê�‡‚É‚Í�Aƒ‚ƒWƒ…ƒ‰�[‚ÌŒû‚ƃXƒvƒŠƒbƒ^‹y‚Ñ�AADSLƒ‚ƒfƒ€�A‚¨‹q—l‚̃pƒ\ƒRƒ“‚ðƒP�[ƒuƒ‹‚Å�Ú‘±‚·‚é�ì‹Æ‚ƂȂè‚Ü‚·�B‚±‚Ì�ê�‡�A•Ç‚ÉŒŠ‚ð‚ ‚¯‚é‚ȂǂÌ�HŽ–‚ÍŽÀŽ{‚µ‚Ü‚¹‚ñ�B
</body>
</html>
For EUC-JP encoding:
From:
email@domain.com
To:
email@domain.com
MIME-Version: 1.0
Content-Type: text/html; charset=EUC-JP
Date: Fri, 25 Apr 2003 08:53:14 -0800 (PST)
Subject: Test
<html>
<head></head>
<body>
Æ£¸¶¤µ¤ó¤Ï¡¢ÀßÄêÎã¤ò .namazurc ¤ËÄɲ䷤ƤϤɤ¦¤«¤È<br>
¤ª¤Ã¤·¤ã¤Ã¤Æ¤¤¤ë¤Î¤Ç¤Ï?
<p>
charset ¤ò hard code ¤¹¤ë¤Î¤ÏÌäÂê³°¤Ç¤¹¤¬¡¢<br>
¸½¾õ¡¢namazu.cgi ¤Ç¤Ï¡¢ContentType ¤Ë½ñ¤¯¤·¤«<br>
¤Ê¤¤¤Ç¤¹¡£<br>
ºÇ¶á¤Î apache ¤Ê¤é¡¢default ¤Ç iso-8859-1 ¤Ê¤Î¤Ç¡¢<br>
Àµ¤·¤¤ charset ¤òÅǤ«¤Ê¤¤¤Î¤Ï¤Þ¤º¤¤¤Ç¤¹¡£
</body>
</html>
The Japanese text is just random stuff from the web cos I don't have IME installed on this machine. The emails both display fine in Outlook, assuming you have the correct fonts installed of course (if you can't display Japanese characters on a website, it probably won't work in email).
Well I hope that helps. Incidentally, it's good form to make HTML emails part of a multi-part MIME message with a text version for those who can't render HTML - of course if you know that all of your users can view HTML emails, you don't have to worry about that.
If you haven't already, you might want to look at:
http://www.faqs.org/rfcs/rfc822.html
http://www.faqs.org/rfcs/rfc1521.html
(also RFC1590 and RFC2045, RFC2046, RFC2047, RFC2048, RFC2049 which go into much more depth).