Sending of letters in the correct coding on PHP

Me often ask how to send letters with help PHP in the correct coding: after sending the letter with Russian letters, on a mail to people comes abrakadabra.


And all the matter is that for mail at us is accepted to use coding KOI8-R, and for a web - Win-1251 (ANSI) - so, and leaves - we send from sites in win-1251, and mailers open it  as KOI8-R...


Outputs{Exits} from a situation suffices. Starting{beginning}, it is possible on itself a web for page it is possible to use coding KOI8-R. But I would not advise it to not do{make} - at some visitors can arise with the coding on the page. So we shall leave this method for lamers, and we apply more graceful, on PHP.


So, what is possible to make? That comes to the first mind - instead of whether easier to recode the message? And in the truth, no there is nothing easier.


Especially in PHP standard procedure - convert_cyr_string (string str, string from, string to) is stipulated; as you already, probably, have guessed, function will recode the text contained in a variable $str from the coding $from in the coding $to. The instruction{indication} of the coding occurs by means of symbols of the latin alphabet, accessible parameters and codings corresponding to them:

?         k - KOI8-R

?         w - Win-1252

?         i - ISO8859-5

?         a - X-CP866

?         d - X-CP866

?         m - X-Mac-Cyrillic


Apparently from the table, in our case, before sending of the message contained in a variable $msg, it{he} needs to be recoded from w in k (from Win-1251 in KOI8-R), it looks so: $msg = convert_cyr_string ($msg, w, k); that's all, now it is possible to send our letter easy.