PHP obtains email instance code based on imap

怪我咯
Release: 2023-03-13 09:48:02
Original
1614 people have browsed it

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:


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
)
Copy after login

Reopen the specified directory:


The code is as follows:

imap_reopen($inbox, $host.'Bulk Mail');
$emails = imap_search($inbox,'ALL');
print_r($emails);
Copy after login

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 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:


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
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template