在建立新的網頁郵件程式時,我必須處理大量的郵件,而其中只有一半是正確編碼的!
通常文字被標記為 ISO,但實際上是 UTF :/
在嘗試了許多解決方案和組合之後,我找到了一種似乎適用於我們所有郵件的方法。也許它對其他人也有用。
<?php
函式 mime_encode($data)
{
$resp = imap_utf8(trim($data));
如果(preg_match("/=\?/", $resp))
$resp = iconv_mime_decode($data, ICONV_MIME_DECODE_CONTINUE_ON_ERROR, "ISO-8859-15");
如果(json_encode($resp) == 'null')
$resp = utf8_encode($resp);
返回 $resp;
}
?>