douganggu4392 2013-01-01 13:26
浏览 41

如果不支持imap fetch mime,如何通过php imap获取charset

I'm wondering how to get the charset via PHP IMAP when imap_fetchmime() isn't supported. I either have a lower version of PHP that doesn't support it or maybe it's deprecated, but it doesn't work for me.

What I basically need is to find out the charset of the email via IMAP, so the output would be:

ISO-8859-1

Or whatever it turns out to be. I don't want to read the whole email to find out, I want to find out what the charset is so I can use the correct encoding.

Here is the code I'm using simplified down for the purpose of this email:

$mailbox = "xxx@gmail.com";
$mailboxPassword = "xxx";

$mailbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX",
mailbox, $mailboxPassword);

mb_internal_encoding("UTF-8");
$subject = mb_decode_mimeheader(str_replace('_', ' ', $subject));

$body = imap_fetchbody($mailbox, $val, 1);
$body = base64_decode($body);

echo $body;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 有没有可以帮我搞一个微信建群链接,包括群名称和群资料群头像那种,不会让你白忙
    • ¥15 stm32开发clion时遇到的编译问题
    • ¥15 lna设计 源简并电感型共源放大器
    • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
    • ¥15 Vue3地图和异步函数使用
    • ¥15 C++ yoloV5改写遇到的问题
    • ¥20 win11修改中文用户名路径
    • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
    • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
    • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题