PHPBuilder - IMAP Mail Reading With PHP3 Page 2



RSS Twitter
Articles Php Functions

IMAP Mail Reading With PHP3 - Page 2

by: Mark Musone
|
July 30, 2000

We'll make a nice and simple 3-script based mail reader.
The first script will be to read in your IMAP username and password. We will use the standard PHP authentication for that.
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");
}

?>
This simply reads in your username and password and redirects you to the read mail 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 up an IMAP connection to the mailserver specified by $MAILSERVER, passing in your username and password.
It then get a list of all the messgae headers and in a loop, prints them all out. Besides printing them out, it also makes each one a link to view.php3, passing it that message number.
view.php3 contains:

<?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 opens up the IMAP connection the same as above, and gets the mail message's header information and prints it out.
It then reads in the body of the mail message and prints that out to the screen.
Thats it! You now have a functional web based mail reader...Hotmail watch out, here comes php! ;^)
--Mark

« Previous Page
1
|
2

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Mark Musone

Comment:



Comment:

(Maximum characters: 1200). You have characters left.