View Single Post
Old 20th January 2003, 10:37 PM   #8 (permalink)
dwilson
Registered User
 
Join Date: Nov 2002
Location: Kansas City MO
Posts: 549
Send a message via ICQ to dwilson Send a message via AIM to dwilson Send a message via Yahoo to dwilson
Re:script to check for new mail

<?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);

?>
__________________
Derik Wilson
dwilson is offline   Reply With Quote