Marking an email unread in PHP IMAP
Asked Answered
P

3

7

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.

Peri answered 10/10, 2012 at 3:25 Comment(1)
Try this out: #1604516Gala
D
8

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); 
Doorstop answered 14/12, 2015 at 9:59 Comment(1)
This answer still holds true however the FT_PEEK flag is invalid. I had to use "\\Seen" and not "//Seen". No errors displayed so took a bit of time to catch this.Milker
C
4

try the imap_clearflag_full ,

imap_clearflag_full($mailbox, $email_number, "\\Seen");
Curkell answered 21/5, 2015 at 5:49 Comment(0)
I
1

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

Illhumored answered 10/10, 2012 at 4:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.