我在用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)
它现在工作得很好。