Emails from Linux with æ, ø and å

Sometimes one need to send an email from Linux (automated messages, warnings and so on).
The problem is that the content looks strange when received by the email clients. The issue could be related to character encoding and UTF8.

Here is a php script I used to send an email with the correct character encoding.

[php]
<?php

# If you are sending the email to several people, sometimes it is good to use BCC (blind carbon copy)

$bcc = "person1@something,person2@something,person3@something";
$subject = "Here is some text with special characters ø æ å";
$body = "Hello, this is the norwegian characters ø, æ and å";
$headers = "From: apache" . "\r\n" .
"Reply-To: me@something" . "\r\n" .
"Bcc: $bcc" . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$header_ = ‘MIME-Version: 1.0’ . "\r\n" . ‘Content-type: text/plain; charset=UTF-8’ . "\r\n";

# Send the email with headers!
mail(”, ‘=?UTF-8?B?’.base64_encode($subject).’?=’, $body, $header_ . $headers);
?>
[/php]

Leave a Reply

Your email address will not be published. Required fields are marked *