'Check new email in gmail inbox using PHP

So my current code is this in PHP:

$mailbox = imap_open('{imap.gmail.com:993/imap/ssl}INBOX', '[email protected]', 'password') or die('Cannot connect to Gmail: ' . imap_last_error());

This code allows PHP to see my email inbox using IMAP and it works fine.

Now my question is, how to make it so that It checks all the new emails in my inbox and outputs "n New Emails!" and marks each of them as seen automatically.

I would really appreciate It If someone were to shed some light on this as I am very new to IMAP and handling emails programmatically in general.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source