When sending mail, I receive in the text of the letter: "the placement in the information system is a protocol ..." is similar, I structure the text into a letter using foreach .. that is, I take it from the array. Shipped as follows:

$message = "<html><body>"; $message .= "<h3 style='text-align:center'>Поздравляем bla .</h3>"; $message .= "<h2 style='text-align:center;'>Ответы</h2>"; foreach ($err_array as $err => $el) { foreach ($el as $item => $val) { $message .= '<h4>Вопрос №'. $err .'</h4>'; $val = htmlentities($errors_to_send[$err]['otvet']); $message .= '<h4>'.$my_questions[$err]['quest']. '</h4>'; $message .= '<p>Правильный ответ:'. htmlentities($my_questions[$err]['answers'][--$val]) .'</p>'; $message .= '<h5>Комментарий :</h5><p>' . htmlentities($errors_to_send[$err]['comment']) .'</p><hr>'; } } $messahe .= "</body></html>" $subject = 'Ответы на тест.'; $headers = "From: admin@bla-bla.ru\r\n"; $headers .= "Reply-To: admin@bla-bla.ru\r\n"; $headers .= "CC: admin@bla-bla.ru\r\n"; $headers .= "Content-Type: text/html; charset=UTF-8\r\n"; $headers .= "MIME-Version: 1.0\r\n"; //ISO-8859-1 попробуем явно указать utf-8 //$headers .= "Content-Type: text/html; charset=utf-8\r\n"; if(mail($_POST["mail"],$subject, $message, $headers)){ echo "<p>Письмо отправлено на почту </p>".$_POST["mail"]; }else echo "<p>mail to ".$_POST["mail"]." return false."; 
  • if you look at the body of the letter that came to the post office ... "Bom symbol" appears cyclically - every ~ four lines ... and does not coincide with the foreach I insert into the information .. - Konstantin Maslov

2 answers 2

Probably your script encoding is not UTF-8. Use the mb_internal_encoding function at the very beginning of the script with installation on UTF-8, or check that the PHP file is in this encoding.

  • It is doubtful. Then everything would have deteriorated altogether, and in arbitrary places there are broken symbols. - Qwertiy
  • on the file - the values ​​of the array. I also thought 2 hours ago .. but no - obviously it's not the point, and message is the body of the letter - you can specify a title. <! DOCTYPE html PUBLIC "- // W3C // DTD XHTML 1.0 Transitional // EN" " w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> - Konstantin Maslov
  • Add code so that you can do .stackoverflow.com/help/mcve (minimal, self-sufficient and reproducible example) - Daniel Protopopov
  • You can reproduce the example on the domain ... seminar-starsof.app-labs.ru in the form of a test .. pass the test - enter the mail .. get errors by mail - Konstantin Maslov
  • But we will not see the code of this minimal and reproducible example to judge what is wrong in it. - Daniel Protopopov
 encodeURIComponent("Ð  ") "%C3%90%20%EF%BF%BD" encodeURIComponent("н") "%D0%BD" 

The space %20 superfluous, the last byte matches the %BD . %EF%BF looks like trash.

Most likely you split a string somewhere in UTF8 between bytes (perhaps by inserting this space itself; or just somewhere reading is not into the byte buffer, but into the string buffer with immediate conversion), after which an automatic attempt is made to restore the broken string to read states.

  • I tried to replace all the text .. in the array - the answer - did not help .. a feeling. that the characters appear randomly .. - Konstantin Maslov