Page 1 of 1

accented characters in From: cc: bcc: subject: fields

Posted: Sun Mar 14, 2010 3:18 pm
by digitalecartoons
How can I have accented characters appear in email header fields? E.g. below mail will send my name 'René'. When I use it and the email arrives, it says 'RenX' in the From field. I've tried different charsets (iso8859-1 and utf-8), but I either get RenA@ in the message text when in html text mode or Ren? when in plain text mode (viewing my mail through webmail). The From: field says RenX in both cases? I'm using it for a flash form, which outputs utf-8 by default. Though I tried iso8859-1 (gave RenA@ so didn't work), I used utf-8 in this case. So when I can make this one display René both in the From: field and message part, my flash form will work too.

But how to do it? Why won't my email's headers display accented/umlauted characters?

Code: Select all

<?php
 
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset= UTF-8\r\n"; 
$headers .= "From: René <email@adres.nl>\r\n"; 
 
$OK = mail('info@testmail.nl', 'A question', 'René is my name', $headers);
 
if ($OK) {
  echo 'sent=OK';
  }
  else {
  echo 'sent=failed&reason='. urlencode('There is a problem with the server. Try again later.');
  }
?>
 

Re: accented characters in From: cc: bcc: subject: fields

Posted: Tue Mar 16, 2010 4:33 pm
by Sofw_Arch_Dev
Sounds like some further debugging is in order. When Flash submits the form and PHP receives the post, what does PHP receive? Have you verified that Flash submits what you expect? Have you tried using PHP's utf8_encode() function to ensure that you're putting UTF-8 strings in your message header and body? Just telling the header that you want UTF-8 is not a guarantee that you'll get UTF-8 strings. BBEdit, for example, has different editing modes and you must set the file you're editing to be UTF-8 in order to edit it as UTF-8.

I suppose you've read php.net's documentation on mail().

Re: accented characters in From: cc: bcc: subject: fields

Posted: Tue Mar 16, 2010 7:42 pm
by Weirdan
As far as I remember you need to encode message headers as quoted-printable (http://en.wikipedia.org/wiki/Quoted-printable) . You can consult SwiftMailer's source to see how it does it (I'm fairly sure it does it properly).