Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IMAP & PHP - Fetching all emails from sent and inbox folders

I am trying to fetch any emails received and sent, and write it to the mySQL database using PHP.

The hostname I am using is:

$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';

Which is referencing just the inbox, and successfully grabs just emails received.

To grab emails sent, I am trying to use this hostname:

$hostname = '{imap.gmail.com:993/imap/ssl}[Gmail]/All Mail';

By replacing "INBOX" with "[Gmail]/All Mail", no emails (not even sent) and being returned.

How do I grab all emails sent and received?

like image 774
steeped Avatar asked Mar 21 '23 08:03

steeped


1 Answers

You can use This code

$host = '{imap.gmail.com:993/ssl}';
$mail_con = imap_open($host, $login, $password);
$mailboxes = imap_list($mail_con, $host, '*');

You can get array like this

Array(
    [0] => {imap.gmail.com:993/ssl}INBOX
    [1] => {imap.gmail.com:993/ssl}Personal
    [2] => {imap.gmail.com:993/ssl}Servers
    [3] => {imap.ipage.com:993/imap/ssl}INBOX.Sent Items
    [4] => {imap.ipage.com:993/imap/ssl}INBOX.Drafts
)

remove above code and Use any array in imap_open like this

 $host = '{imap.gmail.com:993/ssl}INBOX.Sent';
 $mail_con = imap_open($host, $login, $password);
like image 59
Rameshwar Patnaik Avatar answered Apr 01 '23 15:04

Rameshwar Patnaik