Encoding Mail Subjects Properly When Sending Mail With PHP
It is one of the most common bugs in Russian web applications. Nowadays coders do not forget to add Content-type header to mail messages, but many of them forget (or don't know) that this header affects he messag body only. They think, if they specified proper encoding for body, mail client will use it for Subject, too.
Which is totally wrong, of course.
I am speaking about Russian developers, because I only receive mail in Russian and English, and English messages for obvious reasons do not suffer from this problem. I'm sure that other languages suffer as much as Russian do.
So, enough dull talk. What should proper mail Subject be? If encoded if consists of the parts separated by special characters:
=?{original text encoding}?{encoding method}?{encoded subject}?=
So, if you want, for example, to send mail in UTF-8, your message subject should be converted like that:
$subject='=?utf-8?B?'.base64_encode($subject).'?=';
Do not do other people's mistakes.
(Use their experience to make your own ones.)
Nov. 02, 2007 // 14:01 | Comments (0)
![[rss]](images/rss.gif)