Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

gmail

imap

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!

like image 294
Pavel Avatar asked Nov 01 '11 15:11

Pavel


1 Answers

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());
like image 160
AlliterativeAlice Avatar answered Sep 19 '22 21:09

AlliterativeAlice