// This example can be used to practice IMAP functions.
// But if you really want to write webmail, you have to consider more than that ...... Lone Wolf
Login. php3
<? PHP
If (! $ Php_auth_user ){
Header ("www-Authenticate: Basic realm =" email client check "");
Header ("HTTP/1.0 401 unauthorized ");
} Else {
$ Mydir = ereg_replace ("/[^/] + $", "", $ php_self );
Header ("Location: $ SERVER_NAME $ mydir/messages. php3 ");
}
?>
This checks the user and directs the user to the user mail page.
Messages. php3
<? 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> ";
}
?>
Connect to the IMAP server $ MailServer after verification
Then, retrieve the email list and create a connection to read the email.
View. php3:
<? PHP
$ MailServer = "{localhost/IMAP }";
$ Link = imap_open ($ MailServer, $ php_auth_user, $ php_auth_pw );
$ Header = imap_header ($ link, $ num );
Echo "from: $ header [fromaddress] <br> ";
Echo "to: $ header [toaddress] <br> ";
Echo "Date: $ header [date] <br> ";
Echo "Subject: $ header [subject] <br> ";
Echo imap_body ($ link, $ num );
?>
View. php3 open the IMAP connection, obtain the mail header information, and display
This is only a small one.ProgramYou have to write it all by yourself!