fromaddress; $subject = strip_tags($mailHeader->subject); $date = $mailHeader->udate; $today = localtime(); $oldday = mktime(0,0,0, $today[4]+1, $today[3]-$days, $today[5]+1900); if ($date< $oldday) { $numDeleted++; imap_delete($mbox, $i); } } imap_expunge($mbox); imap_close($mbox); return $numDeleted; } $numDeleted = deleteOldSpam("{imap.server.tld:143}INBOX.Spam", "username", "password", 6); echo "$numDeleted emails have been deleted"; ?>