Tuesday, 18 October 2011

Unicode Characters in an Email Subject using PHP and PEAR

I've been working on a PHP site recently where I have had to cater for all languages and more importantly Unicode languages.

So after quite a lot of messing about and hunting around I found that I needed to do the following with the subject:

if (function_exists("mb_internal_encoding"))
 mb_internal_encoding("UTF-8");
if (function_exists("mb_encode_mimeheader"))
 $subject = mb_encode_mimeheader($subject, "UTF-8", "B", "\n");

Obviously if you know if the mb_* functions are available, then you can do away with the if statements.

This works using the PEAR Mail_Mime library. I haven't tested it with the built-in PHP mail function. I would assume it does not work.

No comments:

Post a Comment