I am trying to access Gmail accounts to import Sent and Received Mails in a PHP application. After each import, I store the current date in order to not import all mail each time.
// $this->dateLastSynchro is a DateTime object
$searchCriteria = 'NEW UNDELETED SINCE "' . $this->dateLastSynchro->format('r') . '" ';
$return = imap_search($this->mailBoxHandle, $searchCriteria);
The first import works fine (when I use "ALL UNDELETED"
), but when I use SINCE, I never have results (even if I have sent or received new mails).
I have tried to use the format Y-m-d
for date, but I have a PHP Notice when I do this (it says something like Unrecognized criterion).
Thanks for help.
EDIT
Solution suggested by Max works fine but I can't accept answer because it's a comment.
Perhaps you should store the last UID you got. UIDs are guaranteed to increase as messages are added to the mailbox.