php IMAP Mark as read?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
arya6000
Forum Newbie
Posts: 15
Joined: Fri Apr 07, 2006 3:32 pm

php IMAP Mark as read?

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: php IMAP Mark as read?

Post by pickle »

imap_fetchbody() should be flagging it as "seen" already.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
arya6000
Forum Newbie
Posts: 15
Joined: Fri Apr 07, 2006 3:32 pm

Re: php IMAP Mark as read?

Post 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";
  }
 }
 
Last edited by arya6000 on Fri Jun 26, 2009 12:34 am, edited 1 time in total.
arya6000
Forum Newbie
Posts: 15
Joined: Fri Apr 07, 2006 3:32 pm

Re: php IMAP Mark as read?

Post 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
Post Reply