I am trying to get my gmail inbox messages. I don't want to get all and then select some of them. I have found that there is RECENT flag for imap_search() which can be used to get recent inbox messages.
I have tried by following:
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'xxxxx@gmail.com';
$password = 'xxxxx';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
/* grab emails */
$emails = imap_search($inbox,"RECENT");
It does not show me anything. I have also tried using SINCE for the last 3 days of inbox email like following:
/* grab emails */
$date = date ( "d-M-Y", strtotime ( "-3 days" ) );
$search = 'SINCE "'.$date.'"';
$emails = imap_search($inbox, $search);
It returns me the following Notice:
Notice: Unknown: Unknown search criterion: SINCE (errflg=2) in Unknown on line 0
Please, can anyone tell me what would be the correct syntax or format to get some recent emails from gmail using php and imap ?