note 28919 deleted from function.imap-header by didou
| From: | didou@php.net | Date: | Sun, 14 Jan 2007 23:34:46 +0000 |
| Subject: | note 28919 deleted from function.imap-header by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-121663@lists.php.net to get a copy of this message | ||
Note Submitter: DokFLeed dokfleed at dokfleed dot com
----
After getting lost for days,i gathered all what i could find plus
the codes i tweaked according to the manual , here they go,
all formatted and ready to use ,
this will grab all the messages in a mail box, and read them.
You will need to replace Username & Password by yours, ( i
dont know what the "adl" or why isnt it showing ( codes i
gathered , their credits goes to whoever they belong)
==============================
Start of Code
==============================
//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, click the link
//to read it , passing the message number to the function
//viewmailz
function readmailz(){
$MAILSERVER="{mail.host.com:143}";
or $MAILSERVER="{localhost:143}";
$PHP_AUTH_USER = "USERNAME";
$PHP_AUTH_PW = "PASSWORD";
$mbox=imap_open($MAILSERVER,
$PHP_AUTH_USER,
$PHP_AUTH_PW);
echo "Number of Total Emails: "
.imap_num_msg($mbox);
echo " Number of Recent Emails: "
.imap_num_recent($mbox)."<BR><BR>";
$headers=imap_headers($mbox);
for($x=0; $x < count($headers); $x++) {
$idx=($x+1);
echo $idx." <a href=\"$PHP_SELF?num=$idx\">
$headers[$x]
</a><br>";
}
imap_close($mbox);
}
//viewmailz 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.
function viewmailz($num){
$MAILSERVER="{mail.host.com:143}";
or $MAILSERVER="{localhost:143}";
$PHP_AUTH_USER = "USERNAME";
$PHP_AUTH_PW = "PASSWORD";
$mbox=imap_open($MAILSERVER,
$PHP_AUTH_USER,
$PHP_AUTH_PW);
$header=imap_headerinfo($mbox,
$num,
80,80);
$from = $header->from;
$udate=$header->udate;
$date=Date("F j, Y, g:i a", $udate);
echo "Message Number: ". $num."<br>";
$subject= $header->fetchsubject;
if (is_array($from)){
while(list($key, $val) = each($from)) {
echo "From Address: ";
echo $fromaddr=sprintf("%s@%s",
$from[0]->mailbox,
$from[0]->host).
"<BR>";
echo "Personal : ".
$from[0]->personal.
"<br>";
echo "Adl : ".
$from[0]->adl.
"<br>";
echo "Mailbox : ".
$from[0]->mailbox.
"<br>";
echo "Host : ".
$from[0]->host.
"<br>";
echo "Subject : ".
$subject.
"<br>";
echo "Date : ".
$date.
"<br>";
echo "To Address : ".
$header->toaddress.
"<br><BR><BR>";
}
}
echo imap_body($mbox,$num).
"<br>END OF BODY<br>";
imap_close($mbox);
}
==========================
END OF Code
==========================