Set Unicode Character in Email Subject with PHP

In this quick article we will see how we can set/use Unicode characters in email subject with PHP.

Set unicode character in email subject with PHP

Here I am referring to characters which includes all possible characters, Here are few examples which are very tough to get into email subject. Example: ❤, ★, etc. There are many more unicode characters available, full list can be found here.

So if you try to send all these characters in email subject in simple way then 99.99% you will end up with junk characters in email subject. I have mentioned 99.99% because some email client understand what we want to achieve and it correct our mistake. :)

Now let’s look at the tricky code snippet which enable us to send Unicode characters in email subject with PHP.

// Code without trick
$subject = "I Love You ❤";

// You will end up with junk character in subject
mail("[email protected]",$subject,"This email subject will contain JUNK characters.");

// Code with trick
$subject = "I Love You ❤";
$updated_subject = "=?UTF-8?B?" . base64_encode($subject) . "?=";

mail("[email protected]",$updated_subject,"This email subject should not contain JUNK characters.");

So, I am done with my article, let me know if you have any suggestion/comments/questions on this trick/article.

Related Posts

Written by Avinash

Avinash Zala is leading various projects which deals with the various technology involved with the web. A combination of perfect technical and management skills. Avinash would like to chat with you and convert your imagination into the working system. You can get in touch with him on Facebook and Twitter.

View all posts by: