Mail subject encoding problem
| From: | Thodoris | Date: | Fri, 30 Jan 2009 12:21:56 +0000 |
| Subject: | Mail subject encoding problem | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-287407@lists.php.net to get a copy of this message | ||
Hi gang,
I have developed a web intranet and I have added mail notification when some tasks are done. I am using the mail() function to send mail since no advanced features are needed like attachments. So I am facing a weird problem with the mail subject encoding. Let me explain.
I am having a FreeBSD web server for development that is working like a charm when sending mail using something like this:
// Define the e-mail content
$email = "foo@foo,com";
$subject = "H εργασία: (id: 1868) έκλεισε χωρίς σχόλια.";
$message = "Αυτό είναι ένα τέστ. Αυτό είναι ένα τέστ. Αυτό είναι ένα τέστ.";
// $subject = mb_encode_mimeheader($subject,'iso-8859-1','B');
// Set the headers and send the e-mail
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= "From: test@foo.com\r\nReply-To: test@foo.com\r\nX-Mailer: PHP";
mail($email,$subject,$message,$headers);
The language in both subject and mail body is Greek. But when I am uploading this to a Linux CentOS 5.2 server this mail is being sent but the subject is rubbish.
All encodings are in UTF-8 (the php file, the encoding of the mail client etc) so to solve this I have added the mb_encode_mimeheader line.
This quite many times although sometimes it works. I have also tried to set quoted-printable mime encoding with similar results.
FreeBSD has PHP 5.2.8
Linux has PHP 5.2.5
The php.ini used is almost identical.
Any ideas on this ??
--
Thodoris