PHP obtains email instances based on imap and imap obtains instances.
This example describes how PHP obtains mails Based on imap. 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:
Copy codeThe 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:
Copy codeThe 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:
Copy codeThe 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.