When the form results are sent to the email, it looks unreadable, how can this be corrected? I have already entered the encoding but for some reason it continues to come with broken text. php:

<?php $ToEmail = 'myemail@gmail.com'; $EmailSubject = 'Обратный вызов'; $mailheader = "From: ".$_POST["email"]."\r\n"; $mailheader .= "Content-type: text/html; charset=\"utf-8\""; $MESSAGE_BODY .= "Имя: ".$_POST["name"]."\n"; $MESSAGE_BODY .= "Телефон: ".$_POST["phone"]."\n"; mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure"); ?> 

js:

 $("#callbackForm").submit(function() { $.ajax({ url: "callback.php", method: "POST", data: { name: $("#callbackForm input[name='name']").val(), phone: $("#callbackForm input[name='phone']").val() }, success: function(data) { $("#callbackForm input[name='name']").val(""), $("#callbackForm input[name='phone']").val(""), $("#subCallback").attr("value", "отправлено"); } }); return false; }); 
  • what does broken text mean? Perhaps from the form itself, the text comes in a different encoding, try adding accept-charset = "UTF-8" to the form <form action="" method="post" accept-charset="UTF-8"> - Dmitriy Kondratiuk
  • This is what comes to the email address: 333 - Dima Vleskov

1 answer 1

Check the encoding in three places:

1) Sender coding (your form). Set her header utf-8 encoding. <head><meta charset="utf-8"></head> .

2) Submission form. In the submission form, also make the default input encoding <form action="" method="post" accept-charset="UTF-8">

3) Receiver coding. Your Callback.php . Specify the following information for php in the file: mb_internal_encoding("UTF-8");

Make sure that the settings of your Nginx (Apache) are set to utf-8.

Well and everything else, save your executable files in UTF-8 without BOM format UTF-8 without BOM