Notes on Java, Solaris, PHP, LDAP…

September 11, 2008

Generating Unicode email via mailto: link in Javascript

Filed under: Java — negev @ 11:28 am

I wanted to generate mailto: link with a subject and body which contained Unicode characters. As an example for Unicode letters I was getting following from a PHP form. The application workflow required that I process any transformation in Javascript rather than on server.

That stands for nice Korean 매뉴얼:
javascript:alert( unescape(‘%uB9E4%uB274%uC5BC’) )

which in HTML Unicode escapes is (following without spaces, otherwise WordPress shows them as Korean letters):
& #xB9E4;& #xB274;& #xC5BC;

javascript:alert( ‘%EB%A7%A4%EB%89%B4%EC%96%BC’ )
-> same Korean letters

javascript:alert( escape(‘%EB%A7%A4%EB%89%B4%EC%96%BC’ ) )
-> %uB9E4%uB274%uC5BC

javascript:alert( encodeURI(‘매뉴얼’ ) )
-> %EB%A7%A4%EB%89%B4%EC%96%BC

So my final transformation was:
var encodedSubject= encodeURI( unescape( ‘%uB9E4%uB274%uC5BC’) );
var encodedBody= encodeURI( unescape( ‘%uB9E4%uB274%uC5BC Lala lala’) );
javascript:window.location.href= ‘mailto:?subject=’ +encodedSubject;+ ‘&body=’ +encodedBody;

I’ve also tried following to  generate HTML escapes of Unicode characters, but it doesn’t work for URLs:

function url_encoded_unicode_to_html( url ) {
var regex_search= new RegExp( “%u([0-9a-fA-F]{4,4})”, “g” );
var regex_replace= ‘&#x$1;’;

return url.replace( regex_search, regex_replace ); //( ‘/%u([0-9a-fA-F]{4,4})/’, ‘&#x$1;’, $text );

Unicode emails via PHPMailer

Filed under: Java — negev @ 10:58 am
Tags: ,

My web app has a form and then it sends emails via PHPMailer. But it didn’t work for Unicode messages.

I added accept-charset=”utf-8″ to the <form> tag. Then I changed $CharSet setting from default ‘iso-8859-1’ to ‘utf-8’. That worked for Unicode email body, but not for Unicode subject. In order to get Unicode subjects work I had to update PHPMailer to version 2.0.2.

var $CharSet           = ‘utf-8′; //’iso-8859-1’;
var $ContentType        = ‘text/plain’;
var $Encoding          = ‘8bit’;

Blog at