Currently I am using following code which can retrieve INBOX email messages easily.
<?php
$username = '[email protected]';
$password = 'ExamplePassword';
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());
$emails = imap_search($inbox,'ALL');
rsort($emails);
foreach($emails as $email_number)
{
$overview = imap_fetch_overview($inbox,$email_number,0);
print_r($overview);
echo "<br><br><br>";
}
imap_close($inbox);
?>
Now I want to filter primary tab messages as well.
How to filter gmail primary mails using imap php.
what I tried:
Not sure how do I make it work:
https://www.toptal.com/php/building-an-imap-email-client-with-php
$ids = $imap_driver->get_uids_by_search(' X-GM-RAW "category:primary"');
if ($ids === false) {
echo "get_uids_failed: " . $imap_driver->error . "
";
return false;
}
question from:
https://stackoverflow.com/questions/66061234/read-gmail-primary-mails-using-imap-php 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…