tags:

views:

233

answers:

5

I have the following php in my contact form.

// Ensure a message was entered, then sanitize it
if(!empty($_POST['cf_m']) && $_POST['cf_m']!='Enter Your Message Here')
{
 $message = strip_tags($_POST['cf_m']);
}

When I receive a message by email, Norwegian characters, å, ø and æ becomes Ã¥, ø, æ

What can I do in order to show correct characters?

+1  A: 

You must set the encoding in the mail header, like it's explained in the php-comments on mail() (http://de.php.net/manual/de/function.mail.php):

<?php
function mail_utf8($to, $subject = '(No subject)', $message = '', $from) {
  $header = 'MIME-Version: 1.0' . "\n" . 'Content-type: text/plain; charset=UTF-8'
    . "\n" . 'From: Yourname <' . $from . ">\n";
  mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header);
}
?>
schneck
+6  A: 

It appears your form is served as UTF-8, but the e-mail is sent as ISO-8859-1 (or another variety). You may want to explicitly set the character encoding of the sent e-mails by setting the Content-type header, for example:

Content-type: text/plain; charset=UTF-8

Set the $additional_headers parameter of the PHP mail() function to accomplish this.

molf
A: 

I think that those characters are UTF8 encoded so you can use the utf8_decode function to show them right

mck89
A: 

Use UTF-8 throughout your code. For me, this page was very helpful.

Martijn
A: 

This is about sending an email with norwegian characters?
Take a look at SwiftMailer, it's a great library for handling emails. Setting the message's charset is described at http://swiftmailer.org/docs/message-charset. (And since utf-8 is SwiftMailer's default you don't have to do anything in your case.)

VolkerK