Jump to content

Problems with umlaut ü ö


pwired
 Share

Recommended Posts

Hi

I have this part in a php form:


"Danke für Ihre Bestellung bei\n" .

//$msg2 with contents for the client

$msg2 = "=======================================\n" .
"Danke für Ihre Bestellung bei\n" .
"---------------------------------------\n" .
"Bitte überweisen Sie den\n" .
"\n" .

If the form is sent, both the webshop owner and the client recieve an email.

So far so good.

Only the ü in für and the ü in überweisen appear garbled (strange characters)

in the received email.

I tried setlocale(LC_ALL, "de_DE.UTF-8"); in the php form

and I do not have setlocale(LC_ALL, "de_DE.UTF-8"); in config.php

But that did not help.

Link to comment
Share on other sites

Ok got it working with this:

mail($emailTo, "Bestellung", $msg1, $header = "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n");

Now the ü appears correctly in the received emails.

Can anyone confirm that this is 100 % code tight ?

Edit: tried a few test orders and all looks well

in the received emails with ü and ö

Link to comment
Share on other sites

I thinks it's not exactly your question, but I also remember a lot of problems with php mail and encoding…

If every thing works in the body part of the mail, but you have issues with umlauts in the subject try:

$subject = '=?UTF-8?B?'.base64_encode($subject).'?=;

Good luck :)

  • Like 2
Link to comment
Share on other sites

Ah, OK. Well, that depends on where the $msg1 and $emailTo fields come from and if you trust them to never have anything malicious in them. If they can have something malicious (like a frontend user entering an email address, or anything that gets made part of $msg1) then, no, this is definitely not "code tight".

Always sanitize user input. Please look at PWs sanitizer class; it has methods specifically for making email addresses and general text more "code tight."

It's also not code tight as it totally ignores the return value of the mail() call - so you'll never know if the send failed. You can also simplify your example by getting rid of the assignment to $header in the call. Here's the last two points put together. I'll leave the sanitization research to you as it's important you find out about it.

$result = mail($emailTo, "Bestellung", $msg1, "MIME-Version: 1.0\r\nContent-type: text/plain; charset=UTF-8\r\n");

if (!$result) {
    // email send failed.
} else {
    // send succeeded
}
  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...