<?PHP
// Open your mailbox
$mailbox = imap_open("{mail.yourdomain.com}INBOX",& quot;yourusername@yourserver.com","yourp assword"

;
// initialize $numMsg with the number of total messages in your box
$numMsg = imap_num_msg ($mailbox);
// If you have some then go ahead and process
if ( $numMsg > 0 )
{
// Loop until you equal or exceed the number of messages you have
for ($i = 1; $i <= imap_num_msg($mailbox); $i++)
{
$header = imap_header($mailbox, $i);
// This checks if you have recent mail or unread mail.
// Recent == 'N' means recent and unread. Unseen == 'U' means yes you have unread mail
if ($header->Recent == 'N' || $header->Unseen == 'U')
{
// you musta had some current unread messages so send yourself an email containing the subject and sender
$mailTo = "youremail@yourserver.com";
$mailSubject = "$header->subjectn";
$mailBody = $header->subject;
$mailBody .= $header->fromaddress;
$mailHeaders = "From: root@$SERVER_NAME.comn";
if (mail($mailTo, $mailSubject, $mailBody, $mailHeaders))
{
print("Mail successfull sent to $mailTo."

;
}
else
{
print("Mail not successfull sent to $mailTo."

;
}
}
}
}
imap_close($mailbox);
?>