I would like to be able to send e-mails with PHP mail() containing the 8-bit characters åäö. They will be used in the subject, the message and in the "From:"-header. How can I do this without using the PEAR packages?
+1
A:
Simplest solution if you don't mind encoding even words that don't need it is to put everything in a base64 RFC 2047 encoded-word:
$subject= "=?utf-8?b?".base64_encode($subject)."?=";
$body= "blah blah $utf8text blah";
$headers= "MIME-Version: 1.0\r\n";
$headers.= "From: =?utf-8?b?".base64_encode($fromname)."?= <$fromaddress>\r\n";
$headers.= "Content-Type: text/plain;charset=utf-8";
mail($toaddress, $subject, $body, $headers);
bobince
2009-09-30 21:25:15
Thank you, but that answer was rather incomplete. I need to use åäö in the message, the "From:" header and the subject. How can I do that? Thanks for your time.
Johan
2009-09-30 22:05:07
Added more context. The From header is just the same method of encoding as the Subject header. The mail body encoding is controlled by Content-Type. I'm taking it as read that you have already have your åäö characters encoded as the UTF-8 byte string '\xc3\xa5\xc3\xa4\xc3\xb6'.
bobince
2009-09-30 22:37:39