The second day, I can not understand what is wrong with the code. The problem of displaying a letter sent from the site is, both in Yandex and in mail.ru, only displayed in different ways. Here is the handler code:

<?php header('Content-type: text/plain; charset=UTF-8'); $mail = "direct-free@yandex.ru"; $subject = iconv('UTF-8', 'cp1251', "Моба: письмо отправленное с сайта"); $header = "Content-type: text/plain; charset=\"UTF-8\""; $header .= "From: " . $mail; $header .= "Subject: " . $subject; $header .= "Content-type: text/plain; charset=\"UTF-8\""; $message = iconv('UTF-8', 'cp1251', "Имя: ") . $_REQUEST['Name'] . iconv('UTF-8', 'cp1251', "\nПочта: ") . $_REQUEST['Email'] . iconv('UTF-8', 'cp1251', "\nТелефон: ") . $_REQUEST['Phone'] . iconv('UTF-8', 'cp1251', "\nТема: ") . $_REQUEST['Subject'] . iconv('UTF-8', 'cp1251', "\nСообщение: ") . $_REQUEST['Message']; $result = mail($mail, $subject, $message, $header); echo "<!DOCTYPE html>"; echo "<html><head>"; echo '<meta http-equiv="Content-Type" content="text/html; charset=\"UTF-8\">'; echo "<title>Моба</title>"; echo "</head>"; echo "<body>"; echo $result ? "Ваше сообщение отправлено." : "При отправке заказа возникла ошибка. Пожалуйста, попробуйте позже."; echo "</body>"; echo "</html>"; ?> 

Here is the form code:

  <form role="form" method="post" id="contact-form"> <input type="text" placeholder="Ваше имя" name="Name" id="Name" required> <input type="email" placeholder="Email" name="Email" id="Email" required> <input type="text" placeholder="Номер телефона" name="Phone" id="Phone"> <input type="text" placeholder="Тема сообщения" name="Subject" id="Subject"> <textarea placeholder="Сообщение" name="Message" id="Message" required></textarea> <button type="submit" id="submit">Отправить</button> <div id="success"></div> </form> 

Screenshots of what the output attached. Any thoughts who? Yandex Mail.ru

    2 answers 2

    So you recode only part of the information, function iconv. Your whole page transmits data to UTF-8, then in a script, you transform a part of it into Cyrillic, part of the data that you will have in the letter remain in UTF-8. So it turns porridge.

    • remove this function or re-encode all the parameters and it is still important what encoding of the file with the script is - Konstantin
    • Got it! Everything fell into place. Thank! - Vladimir

    You have all UTF8 then you alter in cp1251 and you write headlines in all utf8

    in theory, now you just need to remove all iconv. Or if you want to send for some reason in cp1251 you need

      $header = "Content-type: text/plain; charset=\"UTF-8\""; 

    rewrite to

      $header = "Content-type: text/plain; charset=\"cp1251\"";