IwBre
IwBre

Reputation: 1

PHP IMAP retrieve UNSEEN emails from server

I am working on a Cron job script that collects Unseen emails from Google imap server to my database. But sometimes, some emails are not read, so they don't get saved into the database. Here is the code:

$connection = imap_open ($imapaddressandbox, $imapuser, $imappassword)
        or die("Can't connect to '" . $imapaddress .
        "' as user '" . $imapuser .
        "' with password '" . $imappassword .
        "': " . imap_last_error());

$m_search=imap_search ($connection, 'UNSEEN');
if($m_search === false){
email_log("No New Messages ");
}

It seams like for some reason some emails get skipped although they are unread.

Can anyone have an idea why?

Just a note, email is like [email protected], but using google email.

Thanks

Upvotes: 0

Views: 1764

Answers (2)

Thyagi
Thyagi

Reputation: 190

use

 imap_open($incoming_server,$username, $password,FT_PEEK);

Upvotes: 1

superbarney
superbarney

Reputation: 43

Try

if (!$m_search) {
    // No new mails found
}

Upvotes: 0

Related Questions