How to recode sent messages to blessed UTF-8? The form handler sends to the mail messages of the form of the form of a message that seems to be a CP1252 encoding. I tried to solve the problem using the iconv function, but as a result I get only empty letters with no content at all.

<?php header("Content-Type: text/html; charset=utf-8");?> <?php $text=""; foreach($_POST as $key=>$val) { $text=$text." ".$key.":".$val." "; } //$text = iconv('utf-8', 'CP1252', $text); $title = "sendform" ; $to = 'xxx@yandex.ru'; $from='noreply@gyroshop'; if(mail($to, $title, $text, 'From:'.$from)) include("send.html"); ?> 

    2 answers 2

    In your case, you need to add a header. And there prescribe Content-Type:

     <?php header("Content-Type: text/html; charset=utf-8");?> <?php $headers= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8"; $text=""; foreach($_POST as $key=>$val) { $text=$text." ".$key.":".$val." "; } //$text = iconv('utf-8', 'CP1252', $text); $title = "sendform" ; $to = 'xxx@yandex.ru'; $from='noreply@gyroshop'; if(mail($to, $title, $text, 'From:'.$from, $headers)) include("send.html"); ?> 
    • Does not help. Anyway, come krakozyabry. FIRST SESSION - mxd
    • one
      Solutions like $text= mb_convert_encoding($p,mb_detect_encoding($p , "CP1252"), 'UTF8'); $text= mb_convert_encoding($p,'UTF8', "CP1251"); $text= mb_convert_encoding($p,mb_detect_encoding($p , "CP1252"), 'UTF8'); $text= mb_convert_encoding($p,'UTF8', "CP1251"); don't work either - the line comes in general - mxd
    • one
      Your answer helped to think in the right direction. - mxd

    The problem was the incorrect spelling of the fourth value of the mail() function

    It was correct to write:

     echo mail($to, $title, $text,$headers);