There is such a function for sending messages:

public function send_email($email, $mess) { $subject = 'Проверка работы рассылки'; // mail($email, 'sd', $mess, 'From:'.$from); $headers = "MIME-Version: 1.0\n" ; $headers .= "Content-type: text/html; charset=UTF-8; \r\n"; //$headers .= "From: $from\r\n"; $subject = "=?UTF-8?B?".base64_encode($subject)."?="; @mail($email, $subject, $mess, $headers); } 

I send messages by inserting into HTML a template with such a header:

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1251"> <meta name="viewport" content="width=device-width, initial-scale=1"> <!-- So that mobile will display zoomed in --> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <!-- enable media queries for windows phone 8 --> <meta name="format-detection" content="telephone=no"> <!-- disable auto telephone linking in iOS --> 

If the word is written in the template, then Russian characters are normally visible, and if I take from the database (there is UTF-8 encoding), then all Russian characters fly to the question marks "????????? ....". I have already tried to set the windows-1251 and CP1251 encoding in the message sending function, nothing has helped.

  • If you are given an exhaustive answer, mark it as correct (a daw opposite the selected answer). - Nicolas Chabanovsky

2 answers 2

Well, first try before receiving the data from the query.

  SET NAMES utf8 

If it does not help, then divide the task into two. First, display your template simply in the browser, and when it starts to be displayed normally, then try sending it by letter.

  • Thanks you! now it is displayed normally, but by-by-byes come to the post anyway ... - modelfak

Just in case, look at the popular extended email solution. https://github.com/PHPMailer/PHPMailer