I offer the following example because it took me HOURS to figure this out
<?php
$this->mailInBox = imap_open($this->mailConnectString."INBOX", $this->accountLogin, $this->accountPassword);
$this->messageCount = imap_num_msg($this->mailInBox);
echo "Processing " . $this->messageCount . " messages:<Br>";
for ($i = 1; $i <= $this->messageCount; ++$i) {
$header = imap_header($this->mailInBox, $i);
$prettydate = date("jS F Y", $header->udate);
$fromHost = $header->from[0]->host;
if (isset($header->from[0]->personal)) {
$personal = $header->from[0]->personal;
} else {
$personal = $header->from[0]->mailbox;
}
$body = imap_fetchbody($this->mailInBox, $i, "1.1");
if ($body == "") {
$body = imap_fetchbody($this->mailInBox, $i, "1");
}
$move = "INBOX.processed" . date("Ymd");
echo "trying to move:" . $i . "<br>";
@imap_mail_move($this->mailInBox, $i, $move);
}
?>