Dear all,
I having problem for sending subject in cheses language using mail(), Can anyone let me know how to send send non unicode subject ?
Thanks
Serena
Did you try
changing the header of the message when using the mail() function?
I found some information at PHP.net under the mail section.
Mail header fields and subject allow only ascii characters. You have to encode the subject line to ascii characters from your encoding yourself. You can use Quoted prinables "Q", or "B" base64.
Base64 is easier, and PHP has a built in function
[PHP]
<?php
//specify a character set
$charset = "GB2312";
$to = 'example@example.com';
$subject = 'some chinese text'
//this is the encoded subject;
$encoded_subject = "=?$charset?B?".base64_encode($subject)."?=\n" ;
$message = 'some chinese text';
//HEADERS
$header .= "X-Mailer: Whatever you want\n";
$header .= "Return-Path: <someperson@example.com>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "From: Some Person <someperson@example.com>\n";
//I believe that language code for chinese is cn
$header .= "X-Accept-Language: cn\n";
//This header should make sure that the message has a Guobiao
//encoding
$header .= "Content-Type: text/plain; charset={$charset}\n";
//I'm not an expert, but depending on the character set you use
//you may want to change the transfer encoding.
//I found that GB2312 is 7 bit, so I believe you can
//leave this header out. If you choose another encoding
//make sure the transfer encoding is correct.
//$header .= "Content-Transfer-Encoding: 8bit\n";
//Print error if mail doesn't work, otherwise print successful message
if(!mail($to, $encoded_subject, $message, $header)) {
echo "Error: Message not sent";
}
else {
echo "Message sent successfully!";
};
?>
[/PHP]
The main answer to your question lies in the $encoded_subject variable.
=?$charset?B?".base64_encode($subject)."?=\n
Just specify the character set you want and use the base64_encode function to encode your $subject.
I do a lot of Japanese pages, and I tested a similar version of this script with a japanese encoding and it came out fine.
Hopefully this helps, and let me know if it works