PHP Mail with German umlaut and utf-8 data from a database
Ever had problems with german umlaut and data from mysql in mail subject and mail text?
Here is my solution:
//mailheader ….
$mailheader =’MIME-Version: 1.0′ .”\n”;
$mailheader.=’From: from@domain.net’ . “\n”;
$mailheader.=’Reply-To: to@domain.net’ . “\r\n”;
$mailheader.=’X-Mailer: PHP/’ . phpversion().”\n”;
// Next Line solves only the utf-8 problem within the mail text
$mailheader.=”Content-Type: text/plain; charset=UTF-8\n”;
$mailheader.=”Content-transfer-encoding: 8bit\n”;
// The subject needs to be ASCII 7 Bit
// First: decode utf-8 Data from myql database
$subject=”Example Mail für: “.utf8_decode($firstname.” “.$secondname);
// second: encode subject to ASCII
$subject=mb_encode_mimeheader( $subject, mb_internal_encoding(),”B”,”\n”);
$mailtext=”…….
–snip–
mail(‘address@domain.net, $subject, $mailtext, $mailheader);