| Start | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Connecting to a mailbox To do anything with an IMAP account you need to connect to it first. To do this you need to specify some required parameters:
Your connection string will look something like this: Please note that if any of the characters in your connection string is non-ASCII it must be encoded with utf7_encode($string) (opens new window). To connect to the mailbox, we use the imap_open (opens new window) command which returns a resource value pointing to a stream: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Install IMAP extension To use the IMAP functions (opens new window) in PHP you'll need to install the IMAP extension: Debian/Ubuntu with PHP5 Debian/Ubuntu with PHP7 YUM based distro Mac OS X with php5.6 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| List all folders in the mailbox Once you've connected to your mailbox, you'll want to take a look inside. The first useful command is imap_list (opens new window). The first parameter is the resource you acquired from The output should look similar to this You can use the third parameter to filter these results like this: And now the result only contains entries with Note: Using |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Finding messages in the mailbox You can return a list of all the messages in a mailbox using imap_headers (opens new window). The result is an array of strings with the following pattern: Here's a sample of what each line could look like:
Note that this call could take a fair amount of time to run and may return a very large list. An alternative is to load individual messages as you need them. Your emails are each assigned an ID from 1 (the oldest) to the value of There are a number of functions to access an email directly, but the simplest way is to use
|
Read Article
https://develop.horje.com/learn/1434/reference