PHP Mail corrupts German characters or newlines

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
POPDUM
Forum Newbie
Posts: 2
Joined: Thu Feb 21, 2008 1:03 pm

PHP Mail corrupts German characters or newlines

Post by POPDUM »

Hi,

I have to send email containing German characters (e.g. umlauts). I already had a script which worked with English characters, but it would mess up the German ones.

So, I decided to use encoding in the header, and encoded it to UTF-8 as text/html (using text/plain does not work). Now, the German characters appear OK, but the newlines get lost. I tried using \n and \r\n as newline characters, but it does not work.

Here is the code fragment which I am using:

$name = $_POST['sendername'];
$telefon = $_POST['telefon'];
$message = $_POST['message'];
$email = $_POST['email'];
$typedcode = $_POST['typedcode'];
$body = "* Name:\n$name\n\n".
"* Email:\n$email\n\n".
"* Telefon:\n$telefon\n\n".
"* Anfrage:\n$message";

$result = 'ok';
mail("myname@gmx.net", "Kontaktformular", $body, "From: $email\n" .
"MIME-Version: 1.0\n" . "Content-type: text/html; charset=utf-8\n" );

As I said above, I tried using \r\n too, but it does not work.

Any answers or suggestions are most welcome.
kryles
Forum Contributor
Posts: 114
Joined: Fri Feb 01, 2008 7:52 am

Re: PHP Mail corrupts German characters or newlines

Post by kryles »

the content is text/html so what about trying <br />?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP Mail corrupts German characters or newlines

Post by Jonah Bron »

Good point, Kryles. Neither \n or \r\n should work, because you are sending an html page.
POPDUM
Forum Newbie
Posts: 2
Joined: Thu Feb 21, 2008 1:03 pm

Re: PHP Mail corrupts German characters or newlines

Post by POPDUM »

Thanks very much kryles and PHPyounster; <br /> did the trick!
Post Reply