问题
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?
回答1:
You probably need to do this in two calls, inbox and sent items. According to this post: GMAIL sent folder not accessible using IMAP, the sent items folder is called [gmail]/sent mail
回答2:
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);
回答3:
Actually this is very simple to fetch mails from all these folders, what you have to do is just make an folder extension like .Sent, .Drafts etc..
Example:
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX.Sent'; //For Sent Items<br>
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX.Drafts';//For draft<br>
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX.Trash';//For trash<br>
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX.Junk';//For junk<br>
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX.yourfolder';//For the folders u created
来源:https://stackoverflow.com/questions/20500077/imap-php-fetching-all-emails-from-sent-and-inbox-folders