PHP obtains email instances based on imap and imap obtains instances.

Source: Internet
Author: User
Tags imap

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.

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.