getting the value of Message-ID from gmail imap with php

六月ゝ 毕业季﹏ 提交于 2019-12-21 12:08:03

问题


I use standard imap functions to grab mails, I need to keep track of the Message-ID (and References and In-Reply-To) to build threads. I reply to messages through the smtp, keeping the old subject, but in my web interface is not group them with others. If I add a In-Reply-To header - everything is OK.

The problem is that I can't get values of Message-ID, References, In-Reply-To (but in web interface they are present). I've tried different functions (imap_headerinfo, imap_fetchheader, imap_fetch_overview), but all of this values ​​are empty.

Please help!


回答1:


The message ID is in a format like:

<OTJMCQtXnqgMaP1rLJi-cD9IvuH+xuVndE-DoWAZB0cbdffqHdw@mail.gmail.com>

which is parsed by the browser as an HTML tag, the following code will output a message ID in a way that can be displayed by the browser:

$this->mbox = imap_open('{imap.gmail.com:993/imap/ssl}', $email, $password);
$headers = imap_header($this->mbox, 1);
echo htmlentities($headers->message_id);

Or if you absolutely must use print_r:

$this->mbox = imap_open('{imap.gmail.com:993/imap/ssl}', $email, $password);
ob_start(); 
print_r(imap_header($this->mbox, 1));
print_r(imap_fetch_overview($this->mbox, 1));
print_r(imap_fetchheader($this->mbox, 1));
echo htmlentities(ob_get_clean());


来源:https://stackoverflow.com/questions/7968405/getting-the-value-of-message-id-from-gmail-imap-with-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!