PHP IMAP 解码 UTF-8 电子邮件正文

PHP IMAP Decode UTF-8 email body

我在使用 PHP 解码电子邮件正文时遇到问题。 我有 2 封 UTF-8 电子邮件,其结构相同。 我可以用 iconv("UTF-8", "Windows-1252", $data) 解码正文 对于另一个,这是行不通的。 1)我不知道用什么代替这个 2) 我如何动态区分这两种类型的电子邮件?

stdClass Object
(
    [type] => 1
    [encoding] => 0
    [ifsubtype] => 1
    [subtype] => MIXED
    [ifdescription] => 0
    [ifid] => 0
    [ifdisposition] => 0
    [ifdparameters] => 0
    [ifparameters] => 1
    [parameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => BOUNDARY
                    [value] => ----=_Part_8432_30170987.1457360103746
                )
        )

    [parts] => Array
        (
            [0] => stdClass Object
                (
                    [type] => 0
                    [encoding] => 4
                    [ifsubtype] => 1
                    [subtype] => PLAIN
                    [ifdescription] => 0
                    [ifid] => 0
                    [lines] => 50
                    [bytes] => 1811
                    [ifdisposition] => 0
                    [ifdparameters] => 0
                    [ifparameters] => 1
                    [parameters] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [attribute] => CHARSET
                                    [value] => UTF-8
                                )

                        )

                )



        )

)


stdClass Object
(
    [type] => 1
    [encoding] => 0
    [ifsubtype] => 1
    [subtype] => MIXED
    [ifdescription] => 0
    [ifid] => 0
    [ifdisposition] => 0
    [ifdparameters] => 0
    [ifparameters] => 1
    [parameters] => Array
        (
            [0] => stdClass Object
                (
                    [attribute] => BOUNDARY
                    [value] => ----=_Part_1135_19111967.1451925068339
                )

        )
    [parts] => Array
        (
            [0] => stdClass Object
                (
                    [type] => 0
                    [encoding] => 4
                    [ifsubtype] => 1
                    [subtype] => PLAIN
                    [ifdescription] => 0
                    [ifid] => 0
                    [lines] => 27
                    [bytes] => 490
                    [ifdisposition] => 0
                    [ifdparameters] => 0
                    [ifparameters] => 1
                    [parameters] => Array
                        (
                            [0] => stdClass Object
                                (
                                    [attribute] => CHARSET
                                    [value] => UTF-8
                                )
                        )
                )
        )
)

当我在两个数据对象上使用 imap_mime_header_decode 时,我得到了这个:

Array
(
    [0] => stdClass Object
        (
            [charset] => default
            [text] =>
...
)

提前致谢, 斯蒂蒂

问题已解决: 我用过:

iconv("UTF-8", "Windows-1252//TRANSLIT//IGNORE", $data)

而不是:

iconv("UTF-8", "Windows-1252", $data)

现在效果很好。