On Mon, Apr 30, 2012 at 1:04 AM, Coiby Xu <coiby.xu@xxxxxxxxx> wrote: > Hi all, > > I wonder why mb_encode_mimeheader function can't deal with long non-english > strings. Here are the codes: > >> function util_encode_mimeheader($headername,$str,$charset) { >> if (function_exists('mb_internal_encoding') && >> function_exists('mb_encode_mimeheader')) { >> $x = mb_internal_encoding(); >> mb_internal_encoding("UTF-8"); >> $y = mb_encode_mimeheader($headername . ": " . $str, >> $charset, "Q"); >> mb_internal_encoding($x); >> return $y; >> } >> } > > > According to my tests, if the subject have too many characters, there will > be more than one "?UTF-8?Q??" generated which make the MIME header > invaild. If there are more than one "?UTF-8?Q??" , the remaing "?UTF-8?Q?"s > will appear in the body of email, i.e. the beginning of the email will be: > >> " =?UTF-8?Q?=E6=9C=89=E9=97=AE=E9=A2=98?= >> Content-type: text/plain; charset=UTF-8 ....". > > > Can anyone explain this? > > Thanks! Hi, I guess this limit is somewhere around 75 characters? If so, then this is by design. It is specified in RFC 2047[1], and I quote: "An 'encoded-word' may not be more than 75 characters long, including 'charset', 'encoding', 'encoded-text', and delimiters. If it is desirable to encode more text than will fit in an 'encoded-word' of 75 characters, multiple 'encoded-word's (separated by CRLF SPACE) may be used. While there is no limit to the length of a multiple-line header field, each line of a header field that contains one or more 'encoded-word's is limited to 76 characters." If your mail client displays this wrong, then the mail client is buggy IMO. - Matijn [1] http://www.ietf.org/rfc/rfc2047.txt -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php