PHP letter subject with German letters

I may have a simple problem here, but I don’t understand why it does not work, I have a study and many examples, I publish your current example, I have this from a tutorial where they explain this solution, but in my case this will not work, the subject in the letter that I receive does not display the letter “Ä Ü Ü ß ü” correctly.

$headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/html; charset=utf-8"; $headers[] = "From: {$emailfrom}"; $to = " myemail@yahoo.de "; $subject = 'Betreff mit Ä, Ö und Ü ß ü'; $subject = '=?UTF-8?B?'.base64_encode($subject).'?='; $txt = "Hallo Sie haben das gewählt, am ä "; mail($to,$subject,$txt,implode("\r\n",$headers)); 

Usually they write everywhere in different textbooks, this is the solution, but in my case it does not work, why? Maybe this has something to do with the moon in my case? lol;)

+5
source share
4 answers

You should use mb_encode_mimeheader ,

 mb_internal_encoding("UTF-8"); $subject = mb_encode_mimeheader($subject,'UTF-8','Q'); 

It will take care of coding in Quoted-printable if necessary (human readable). Hope this should solve your problem.

+5
source

Base64 does not need to encode your object ... Just the following works fine:

 <?php $emailfrom = 'Some Name < somename@someserver.com >'; $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/html; charset=utf-8"; $headers[] = "From: $emailfrom"; $to = " myemail@yahoo.de "; $subject = 'Betreff mit Ä, Ö und Ü ß ü'; $txt = "Hallo Sie haben das gewählt, am &#xE4; "; mail($to, $subject, $txt, implode("\r\n", $headers)); 

EDIT: Some headers displayed by Gmail when executing the above code snippet with a Gmail address:

 Subject: Betreff mit Ä, Ö und Ü ß ü X-PHP-Originating-Script: 1000:test.php MIME-Version: 1.0 Content-type: text/html; charset=utf-8 Hallo Sie haben das gewählt, am &#xE4; 
+1
source

So, you need to select one encoding, save the HTML file using this encoding and make sure that you declare this encoding in at least one of the ways. Regarding the use of encoding, Germans usually use ISO / IEC 8859-15, but UTF-8 is a good alternative that can handle any type of character other than ASCII at the same time.

The first ways is to use utf 8

  $headers.="MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n"; 

The second method uses encoding in accordance with the German language

  $headers.= "MIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO/IEC 8859-15\r\n"; 
+1
source
 Try this $headers = array(); $headers[] = "MIME-Version: 1.0"; $headers[] = "Content-type: text/html; charset=utf-8"; $headers[] = "From: {$emailfrom}"; $to = " myemail@yahoo.de "; $subject = 'Betreff mit Ä, Ö und Ü ß ü'; $subject = str_replace(""); $subjects = '=?UTF-8?B?'.$subject.'?='; $txt = "Hallo Sie haben das gewählt, am &#xE4; "; mail($to,$subjects,$txt,implode("\r\n",$headers)); 

If you have the same wrong output means, please refer to iconv () in php, it gives a solution to your problem .. all the best friends ..

-1
source

Source: https://habr.com/ru/post/1260405/


All Articles