This article mainly introduces PHP's method for obtaining mails based on imap. The example details the steps for imap to obtain mails, and describes how to install imap in Windows and Linux, for more information about how to use PHP imap to obtain emails, see the following example. Share it with you for your reference. The specific implementation method is as follows:
Imap is a mail interaction access protocol. the following example uses the php imap module to quickly obtain emails and list 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 );
Print_r ($ mailboxes );
// Result:
Array
(
[0] => Bulk Mail
[1] => Draft
[2] => Inbox
[3] => Sent
[4] => Trash
)
Re-open the specified directory:
The code is as follows:
Imap_reopen ($ inbox, $ host. 'bulk mail ');
$ Emails = imap_search ($ inbox, 'all ');
Print_r ($ emails );
Supplement:
1. install imap in windows
Note that in windows, we need to enable an imap template in php. ini. find the php_imap.dll extension in php and enable it. if you see no extensions, you need to copy the php_imap.dll file.
2. install imap in linux
Finally, complete parameters of the imap compilation module are as follows:
The code is as follows:
./Configure -- with-php-config =/usr/local/webserver/php/bin/php-config -- with-kerberos =/usr -- with-imap-ssl =/usr
Make
Make install
I hope this article will help you with PHP programming.