Envoyer les titres des emails correctement dans un codage autre que ISO-8859. Voir explication ci-dessous:

Now we have an encoded subject, but our mail reader won't know that. So we need to tell it by formatting our subject as follows: "=?" charset "?" encoding "?" encoded-text "?=" , where charset is the original character set and encoding is either "Q" for Quoted-Printable or "B" for Base64.

Examples:
The subject containing the Quoted-Printable ISO-8859-1 string "Voilà une message", is written as:
Subject: =?ISO-8859-1?Q?Voil=E0_une_message?=
The Base64 version of the ISO-8859-1 string is:
Subject: =?ISO-8859-1?B?Vm9pbOAgdW5lIG1lc3NhZ2U=?=
The Quoted-Printable version of the UTF-8 string is:
Subject: =?UTF-8?Q?Voil=C3=A0_une_message?=
The Base64 version of the UTF-8 string is:
Subject: =?UTF-8?B?Vm9pbMOgIHVuZSBtZXNzYWdl?=

"Raw" non-encoded subjects can work and modern mail clients handle it properly, but I found that at least using utf-8 as encoding, the spam analizers complain stating "BAD HEADER Non-encoded 8-bit data". To prevent this, and taking the info above, I decided to use base64, which at least seems to have specific functions (and because it works, of course). So, one could use the following code:

Donc voici ce qu'il faut faire pour tout encoder en base_64:

<?php
...
$charset='UTF-8';
$subject='Subject with extra chars: áéíóú';
$encoded_subject="=?$charset?B?".base64_encode($subject)."?=
";
$to=mail@foo.com;
$body='This is the body';
$headers="From: ".$from."
"
    . "Content-Type: text/plain; charset=$charset; format=flowed
"
    . "MIME-Version: 1.0
"
    . "Content-Transfer-Encoding: 8bit
"
    . "X-Mailer: PHP
";
mail($to,$encoded_subject, $body,$headers);

?>

Solution trouvé sur php.net.