instead of getting all the headers you could just get one at a time: (loop). You might want to sort them also:
$array = IMAP_SORT($imap,1,1);
then get the individual messages by
$msg = IMAP_HEADER($imap,$array[$i]);
(where $i is incrimented in a loop)
after you get each message individually then you can get all your information:
id: $id = imap_uid($imap,$array[$i]);
date: $date = $msg->Date;
from: $from = $msg->from[0];
$personal = $from->personal;
$from = "$from->mailbox@$from->host";
(any of which will do)
Subject: $subject = $msg->Subject;
Size: $size = $msg->Size;
Hope this helps!