encoding - imap_open() in PHP is not handling UTF-8 -
i using php imap functions read mailbox receives utf-8 encoded plain text email (generated server). accented characters replaced question mark (?). below code , following 2 attempts @ fixing it. how fix problem? have no control on server generates messages, claim encoded utf-8. mb_detect_encoding says imap_body function returning ascii string, i've found mb_detect_encoding buggy in past.
$connection = imap_open( '{localhost:993/ssl/novalidate-cert}inbox', 'xxxxxxx', 'xxxxxxx', 0, 1 ); $result = imap_search( $connection, 'unseen' ); if ( $result ) { foreach ( $result $msgno ) { $body = imap_body( $connection, $msgno ); // ... (code process message) ... imap_mail_move( $connection, "$msgno:$msgno", 'inbox.processed' ); } imap_expunge( $connection ); imap_close( $connection ); } }
i tried following convert utf-8, though message utf-8:
$current_encoding = mb_detect_encoding( $body, 'auto' ); // returns "ascii" $body = mb_convert_encoding( $body, $current_encoding, 'utf-8' );
i tried:
$body = mb_convert_encoding( $body, 'utf-8', 'utf-8' );
here solution: got hold of people generating email , made following header changes:
content-type: text/html; charset=utf-8 content-transfer-encoding: quoted-printable
that solved it. php program sees utf-8 characters.
Comments
Post a Comment