I know this one works cause I tested it... sorry about last time probably just missing } or something.
<body>
<?php
echo "Opening IMAP connection\n\n<br>";
$stream = imap_open("{localhost:143}INBOX", "username", "password");
echo "You have " . imap_num_msg ($stream) . " new messages<br>";
if (imap_num_msg($stream) != 0) {
echo "Reading Message<br>";
$array = imap_sort($stream,1,1);
$msg = imap_header($stream , $array[0]);
$from = $msg->from[0];
echo
"$from->mailbox@$from->host<br>";
echo $msg->Subject;
echo "<br><Br>The Message is: ";
echo "<br><br>" . imap_body($stream, $array[0]) . "<br><br>";
}// end if
echo "<br>Closing Stream\n";
imap_close($stream);
?>
</body>