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

1

8

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!

Bathulda answered 1/11, 2011 at 15:0 Comment(5)
Please show your code where you try and use imap_headerinfo(), imap_fetchheader() etc, as these functions are what you should use and should provide the information you want.Catherincatherina
$this->mbox = imap_open('{imap.gmail.com:993/imap/ssl}', $email, $password); print_r(imap_header($this->mbox, 1)); print_r(imap_fetch_overview($this->mbox, 1)); print_r(imap_fetchheader($this->mbox, 1));Bathulda
I have opened a bounty on this question because I want to have access to this header information (specifically Message-ID) to make replying to an email via an IMAP server easy.Dekow
@CarterPape, I suggest starting a new question on the topic given you are adding so much information to the question that it wouldn't be the same question (and it's 2 years old).Mandy
@Mandy I have just done so here. Thanks for the tip.Dekow
E
11

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());
Ernaline answered 25/7, 2013 at 2:56 Comment(4)
Just curious: did you look at the answer that I posted on my own question before coming here to write this answer? If so, no hard feelings; I didn't want the bounty to go to waste.Dekow
I saw your answer, but didn't realize you were the one offering the bounty.Ernaline
Please don't fight :) Thanks for the useful advice. But where have you been 2 years ago? ))Bathulda
Thanks for the question as well as the answer, did anyone figure how to fetch email overviews from message_id of an email , i am currently stuck up wanting to fetch mails in a thread through references which only returns message ids ?Autumnautumnal

© 2022 - 2024 — McMap. All rights reserved.