Read IMAP mail in PHP

Source: Internet
Author: User
Tags date header imap mail
This example can be practiced on IMAP functions
But if you really want to write webmail, there's more to consider than that ... Lone Wolf

Login.php3
<?php

if (! $PHP _auth_user) {
Header ("Www-authenticate:basic realm=" "Mail customer Check");
Header ("http/1.0 401 Unauthorized");
} else {
$MYDIR =ereg_replace ("/[^/]+$", "" ", $PHP _self);
Header ("Location: $SERVER _name$mydir/messages.php3");
}

?>

This user checks and directs the user to the user's 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 an IMAP server after authentication $mailserver

Then get the mailing list and create a connection to read the message

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><br>";
Echo imap_body ($link, $num);

?>

VIEW.PHP3 Open the IMAP connection and get message header information and display

This is only a get to finish the small program, to complete their own to write it!

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.