Use PHP to read IMAP email _ PHP Tutorial

Source: Internet
Author: User
Tags imap
Use PHP to read IMAP emails. 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? Phpif (! $ PHP_AUTH_USER) {Heade // 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

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


$ 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 "$ headers [$ idx]
";
}

?>

Connect to the IMAP server $ MAILSERVER after verification

Then, retrieve the email list and create a connection to read the email.

View. php3:


$ MAILSERVER = "{localhost/imap }";
$ Link = imap_open ($ MAILSERVER, $ PHP_AUTH_USER, $ PHP_AUTH_PW );
$ Header = imap_header ($ link, $ num );

Echo "From: $ header [fromaddress]
";
Echo "To: $ header [toaddress]
";
Echo "Date: $ header [Date]
";
Echo "Subject: $ header [Subject]

";
Echo imap_body ($ link, $ num );

?>

View. php3 open the IMAP connection, obtain the mail header information, and display

This is Only a small program that has been used up. you need to write it on your own!

Else // but if you really want to write WEBMAIL, you have to consider more than that ...... Lone Wolf login. php3? Php if (! $ PHP_AUTH_USER) {Heade...

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.