Hi experts,
I have a strange issue: use php mail function to send mail, the body & subject fields have chinese characetrs, when received the body chinese characters were displayed properly, but the subjetct chinese characters were garbage, any idea? related to php.ini?
Thanks a lot.
Sounds more like you need to set the headers for the email to use chinese characters:
$headers = "From: MyDomain <admin@mydomain.com>\\r\
";
$headers = "To: Whoever <Whoever>\\r\
";
$headers .= "Reply-To: MyDomain <admin@mydomain.com>\\r\
";
$headers .= "Return-Path: <admin@mydomain.com>\\r\
";
$headers .= "MIME-Version: 1.0\\r\
" .
$headers .= "Content-Type: text/plain; charset=UTF-8\\r\
";
$headers .= "Content-Transfer-Encoding: * 8bit\\r\
\\r\
";
Thanks Spence.
//Charlie copied this function from http://www.php.net/function.mail
function encode_cx( $in_str, $charset_str )
{
$out_str = $in_str;
if($out_str && $charset_str )
{
$end = “?=”;
$start = “=?”.$charset_str.“?B?”;
$spacer = $end.“\r
“.$start;
$len = 75 - strlen($start) - strlen( $end );
$len = floor($len/2)*2;
$out_str = base64_encode( $out_str );
$out_str = chunk_split( $out_str, $len, $spacer );
$spacer = preg_quote( $spacer );
$out_str = preg_replace( “/”.$spacer.”$/”, “”, $out_str );
$out_str = $start.$out_str.$end;
}
return $out_str;
}
Use example:
$sMailSubject = encode_cx( $sMailSubject, “utf-8” );
Solved!
Thank you, Spence,