Page 1 of 1

php IMAP Mark as read?

Posted: Mon Jun 22, 2009 1:11 am
by arya6000
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello

I'm using the following code, and I don't know how to mark a message as read after I access it. How can I mark them as read after the program runs?

Code: Select all

$mbox = imap_open("{imap.gmail.com:993/imap/ssl}INBOX", "USERID", "PASSWORD") or die("can't connect: " . imap_last_error());
 $mc = imap_check($mbox);
 $result = imap_fetch_overview($mbox,"1:{$mc->Nmsgs}",0);
 
 foreach ($result as $overview) 
 {
  $seen_msg = $overview->seen;
  if (!$seen_msg)
  {
   echo "{$overview->msgno}\n({$overview->date})\nFrom:{$overview->from}\n{$overview->subject}";
   echo "UID: {$overview->uid}";
   echo "Seen: {$overview->seen}";
   $msgbody = imap_fetchbody($mbox,$overview->msgno,1);
   echo "Message: $msgbody";
  }
 }
 imap_close($mbox);
 

pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: php IMAP Mark as read?

Posted: Mon Jun 22, 2009 10:13 am
by pickle
imap_fetchbody() should be flagging it as "seen" already.

Re: php IMAP Mark as read?

Posted: Tue Jun 23, 2009 12:52 pm
by arya6000
pickle wrote:imap_fetchbody() should be flagging it as "seen" already.
yea, but somehow its not working I even tried the code below and it still does not mark it as read.

Code: Select all

foreach ($result as $overview)
 {
  $seen_msg = $overview->seen;
  if (!$seen_msg)
  {
   echo "{$overview->msgno}\n({$overview->date})\nFrom:{$overview->from}\n{$overview->subject}";
   echo "UID: {$overview->uid}";
   echo "Seen: {$overview->seen}";
   $msgbody = imap_fetchbody($mbox,$overview->msgno,1);
   echo "Message: $msgbody";
   imap_body($mbox, $overview->msgno);
   echo "$overview->msgno";
  }
 }
 

Re: php IMAP Mark as read?

Posted: Tue Jun 23, 2009 1:04 pm
by arya6000
I found the solution, I'll post for others so they don't have to spend so much time searching...

Go to this link http://www.php.net/manual/en/function.i ... g-full.php