Have you ever complained that when you stay in a friend's house or visit a relative, you want to check the email but do not know your POP/IMAP settings. Or worse, they don't have POP or IMAP software?
Web-based emails seem to have been mentioned only recently. Here is how to use PHP to generate a fast, simple and effective IMAP or POP email reader. Once this is done, you can now read your emails from any corner of the world with only one browser.
First, you must know that you have an available IMAP server. You can get the uw imap service software and library functions from ftp://ftp.cac.washington.edu/imap( you will need to compile this library into PHP, so you may also need to install the IMAP service software with the same library ).
Once you have run the IMAP server and compiled PHP with IMAP support (be sure you have read the PHP documentation on how to compile PHP that supports IMAP), the rest will be easy!
We will generate a convenient and simple mail reader program based on three scripts.
The first script will be used to read the user name and password used in IMAP. We will use the standard PHP authentication function.
Login. php3 contains:
--------------------------------------------------------------------------------
<? Php
If (! $ PHP_AUTH_USER ){
Header ("WWW-authenticate: basic realm =" Mail Chek "");
Header ("HTTP/1.0 401 Unauthorized ");}
Else {
$ MYDIR = ereg_replace ("/[^/] + $", "", $ PHP_SELF );
Header ("Location: $ SERVER_NAME $ MYDIR/messages. php3 ");}
?>
--------------------------------------------------------------------------------
It simply reads your username and password and redirects to the email reading page.
Messages. php3 contains:
--------------------------------------------------------------------------------
<? Php
$ MAILSERVER = "{localhost/imap }";
$ Link = imap_open ($ MAILSERVER, $ PHP_AUTH_USER, $ PHP_AUTH_PW );
$ Headers = imap_headers ($ link );
For ($ x = 1; $ x <count ($ headers); $ x ++) {$ idx = ($ X-1 );
Echo "<a href =" view. php3? Num = $ x "> $ headers [$ idx] </a> <br> ";}
?>
--------------------------------------------------------------------------------
It opens an IMAP and connects to the email server specified by $ MAILSERVER to pass your username and password.
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.