Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail subject with german letters

Tags:

php

email

I have here maybe a simple problem, but I don't understand why it doesnt' work, I have research and tried many examples, 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 doesn't 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 = "[email protected]";
$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));

Normally they write everywhere in the different tutorials this is the solution but in my case it doesn't work, why? Maybe have it something to do with the moon in my case? lol ;)

like image 598
UserNameHere Avatar asked Nov 27 '16 10:11

UserNameHere


2 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 encoding to Quoted-printable when needed(the human readable). Hope it should be solve your problem.

like image 103
Faisal Avatar answered Sep 28 '22 03:09

Faisal


So you need to pick one encoding, save the HTML file using that encoding, and make sure that you declare that encoding in at least one of the ways. As for what encoding to use, Germans usually use ISO/IEC 8859-15, but UTF-8 is a good alternative that can handle any kind of non-ASCII characters at the same time.

First ways is that is using utf 8

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

Second Way is using charset according to german language

    $headers.= "MIME-Version: 1.0\r\nContent-Type: text/html; charset=ISO/IEC 8859-15\r\n";
like image 26
Manjot Singh Avatar answered Sep 28 '22 01:09

Manjot Singh