Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Marking an email unread in PHP IMAP

Tags:

php

imap

Are there any PHP IMAP functions which can be used to mark an email as unread? I am checking the mail using some IMAP functions that return the messages as read, but I want to make them unread.

like image 750
faz Avatar asked Oct 10 '12 03:10

faz


3 Answers

To mark an email message as unread, you should unset the \\Seen flag on that message.
You could use the imap_clearflag_full function to clear message flags.

// Unset desired flag
imap_clearflag_full($imap_connection, $message_number, "\\Seen");
// Confirm changes
imap_close($imap_connection, CL_EXPUNGE);

Note:

"I am checking the mail using some IMAP functions that return the messages as read"

You can set the FT_PEEK flag when reading messages, this will not set the \\Seen flag if not already set.

// This will not mark a message as seen
$body = imap_body($imap_stream, $msg_number, FT_PEEK); 
like image 141
Alexander Avatar answered Nov 12 '22 04:11

Alexander


try the imap_clearflag_full ,

imap_clearflag_full($mailbox, $email_number, "\\Seen");
like image 34
Deep Hakani Avatar answered Nov 12 '22 04:11

Deep Hakani


try the imap_setflag_full, http://www.php.net/manual/en/function.imap-setflag-full.php

like image 1
Vidya L Avatar answered Nov 12 '22 02:11

Vidya L