This article mainly introduces the PHP method of obtaining mail based on IMAP, the instance form details the specific steps of IMAP to get the message, and describes in detail the method of installing IMAP under Windows and Linux, and the Friends can refer to the following
This article is an example of how PHP gets mail based on IMAP. Share to everyone for your reference. The implementation method is as follows:
IMAP is a mail interactive access protocol, the following is the main use of PHP IMAP module to quickly get mail, listing all directories, the code is as follows:
The code is as follows:
$host = ' {Imap.mail.yahoo.com:993/ssl} '; $user = ' user@yahoo.com '; $pass = ' password '; $inbox = Imap_open ($host, $user, $ pass); $mailboxes = Imap_list ($inbox, $host, ' * '); $mailboxes = Str_replace ($host, ", $mailboxes);p Rint_r ($mailboxes); /Result: Array ( [0] = Bulk Mail [1] = Draft [2] = = Inbox [3] = = Sent [4] = = Trash)
Reopen the specified directory:
The code is as follows:
Imap_reopen ($inbox, $host. ' Bulk Mail '), $emails = Imap_search ($inbox, ' all ');p Rint_r ($emails);
Add:
1. Windows installation IMAP
Note In Windows we need to open an IMAP template in PHP.ini, find the Php_imap.dll extension in PHP and then turn it on, and if you see extensions there is no need to copy a past Php_imap.dll.
2. Installing IMAP in Linux
The final complete compilation of the IMAP module parameters is as follows:
The code is as follows:
./configure--with-php-config=/usr/local/webserver/php/bin/php-config--with-kerberos=/usr--with-imap-ssl=/ Usrmakemake Install