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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
digitalecartoons
Forum Newbie
Posts: 1
Joined: Sun Mar 14, 2010 3:12 pm

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

Post 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.');
  }
?>
 
User avatar
Sofw_Arch_Dev
Forum Commoner
Posts: 60
Joined: Tue Mar 16, 2010 4:06 pm
Location: San Francisco, California, US

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

Post 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().
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

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

Post 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).
Post Reply