sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php7.2-imap
sudo service apache2 restart
$imap = imap_open('{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX', 'login', 'password');
$emails = imap_search($imap, 'ALL');
if($emails){
echo count($emails);
}
imap_close($imap);