This article mainly introduces the PHP method of obtaining mail based on imap. The example form details the specific steps of imap to obtain mail, and details the installation under Windows and Linux #imap method, friends who need it can refer to it
The example in this article describes the method of obtaining mail in PHP based on imap. Share it with everyone for your reference. The specific implementation method is as follows: imap is a protocol for interactive email access. The following is an example that mainly uses the php imap module to quickly obtain emails and list all directories. 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); print_r($mailboxes); //结果: Array ( [0] => Bulk Mail [1] => Draft [2] => Inbox [3] => Sent [4] => Trash )
imap_reopen($inbox, $host.'Bulk Mail'); $emails = imap_search($inbox,'ALL'); print_r($emails);
1. Windows installation imap
Note that in windows we need to open an imap template in php.ini. Find the php_imap.dll extension in php and open it. At the same time, if you see extensions, php_imap.dll is not turned off. You need to copy the past one.2. Install imap in linux
The final complete compiled imap module parameters are as follows:./configure --with-php-config=/usr/local/webserver/php/bin/php-config --with-kerberos=/usr --with-imap-ssl=/usr make make install
The above is the detailed content of PHP obtains email instance code based on imap. For more information, please follow other related articles on the PHP Chinese website!