Incorrect encoding when sending mail

Here is the program that sends mail to my users:

if (mail( "[email protected]", "",
   " ",
   "[email protected]")) {
   echo " "; 
 } else {
   echo "-  "; 
 }

Everything is sent normally, but there is a problem: the “text” of the message arrives in the wrong encoding. How do I set up the correct encoding?


Answer 1, authority 100%

First of all, you don’t specify what encoding you are using in the email header!

And what is the 4th (“[email protected]”) parameter you have?

if (mail( "[email protected]", "",
   " ",
   "From: [email protected]\r\nMime: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n")) { //   ,    ,     !
   echo " "; 
 } else {
   echo "-  "; 
 }

Answer 2

Each programming language can work with encodings, try manually converting them to a common encoding. For example, this is how I forcefully translate everything into UTF-8 (python) when sending soap:

def mail(to, subject, text_mail, html_text_mail):
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = gmail_user
msg['To'] = to
text = text_mail.encode('utf-8') #