Home >Backend Development >PHP Tutorial >PHP obtains email instances based on imap, imap obtains instances_PHP tutorial

PHP obtains email instances based on imap, imap obtains instances_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:14:29951browse

PHP obtains email instances based on imap, imap obtains instances

The example in this article describes how PHP obtains emails 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:

Copy code 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
)

Reopen the specified directory:
Copy code The code is as follows:
imap_reopen($inbox, $host.'Bulk Mail');
$emails = imap_search($inbox,'ALL');
print_r($emails);

Supplement:

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 that extensions are not connected, php_imap.dll needs to be copied.

2. Install imap in linux

The final complete compiled imap module parameters are as follows:

Copy the code 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 be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/909336.htmlTechArticlePHP obtains email examples based on imap, imap obtains examples. This example describes how PHP obtains emails based on imap. Share it with everyone for your reference. The specific implementation method is as follows: imap is a...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn