2

I want to get emails from gmail, but I want to get the folder 'All Mail'

I have the following:

$server = '{imap.gmail.com:993/ssl}';
$user = 'myUser';
$password = 'myPassword';
$connection = imap_open($server, $user, $password);
$count = imap_num_msg($connection);
echo $count;

The echo however is echoing the emails in the inbox only, how can I make it read a certain folder, or all the folders?

Thank you!

luqita
  • 4,008
  • 13
  • 60
  • 93

2 Answers2

9

Use this to get all mail:

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

We went round and round on this awhile; see here:

https://stackoverflow.com/a/8178514/776695

As stated here, use imap_list to see which individual folders are available

Community
  • 1
  • 1
Ben
  • 745
  • 7
  • 23
4

You can use imap_status to get the message count for a given folder.

To find all folders, you can use imap_list.

To find messages in folders, you can for instance use imap_search. These can then be accessed using e.g. imap_headerinfo and imap_body

For further information, please consult the documentation of the IMAP functions in PHP.

Sebastian Paaske Tørholm
  • 49,493
  • 11
  • 100
  • 118