UserNameHere UserNameHere - 8 days ago 6
PHP Question

PHP mail subject with german letters

i have here maybe a simple problem, but i dont understand why it dont work, i have research and tryed many exampels, i am posting you my current example, i have this from a tutorial where they have explain this is the solution, but in my case it dont work, the subject in the email which i get does not show the letters "Ä Ö Ü ß ü" 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));


Normaly they write everywhere in the differen tutorials this is the solution but in my case it dont work, why? Maybe have it somethink to do with the moon in my case? lol ;)

Answer

You should use mb_encode_mimeheader,

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

It will take care of encoding to Quoted-printable when needed(the human readable). Hope it should be solve your problem.

Comments