show unread mails in mailbox



Hi,

I want to create a small php page on my server which shows me the
number of new (unread) mails in a specific mailbox. Invoking the
script several times for different boxes gives me a list I want.

Until I found the following, but it doesn't work :-(

<?PHP
$mailbox = imap_open("{localhost}","username","password");

$numMsg = imap_num_msg ($mailbox);
if ( $numMsg > 0 )
{
for ($i = 1; $i <= imap_num_msg($mailbox); $i++)
{

$header = imap_header($mailbox, $i);

// This checks if you have recent mail or unread mail.

if ($header->Recent == 'N' || $header->Unseen == 'U')
{
$MailFrom .= $header->fromaddress;
echo $MailFrom;
echo '<BR>';
}
}
}
imap_close($mailbox);
?>

The result of this is the following:

Warning: imap_open() [function.imap-open]: Couldn't open stream
{192.168.1.6} in /opt/lampp/htdocs/portal/tst/test.php on line 3

Warning: imap_num_msg(): supplied argument is not a valid imap
resource in /opt/lampp/htdocs/portal/tst/test.php on line 5

Warning: imap_close(): supplied argument is not a valid imap resource
in /opt/lampp/htdocs/portal/tst/test.php on line 25


What am I missing here?

Many thanks for the missing bit...


Jeroen
.



Relevant Pages