PHP obtains mail instances based on imap

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.