Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

email - read gmail primary mails using imap PHP

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...