Hi,
Please could you help me with this.
I'm trying to retrieve a list of emails from an imap server.
I want them to sort by newest at the top ;
<?php
$server = "server";
$user = "user";
$pass = "password";
$conn = @imap_open("\{$server/imap}INBOX", $user, $pass)
or die("Connection to server really failed");
echo "<table border='0' cellspacing='0' cellpadding='4' id='table1'>
<tr>
<td><font face='Arial' style='font-size: 9pt'>From</font></td>
<td><font face='Arial' style='font-size: 9pt'>Subject</font></td>
<td><font face='Arial' style='font-size: 9pt'>Date</font></td>
</tr>" ;
[B]imap_sort($conn, SORTARRIVAL, 1); [/B]
$headers = @imap_headers($conn)
or die("Couldn't get emails");
$numEmails = sizeof($headers);
// echo "You have $numEmails in your mailbox";
for($i = 1; $i < $numEmails+1; $i++)
{
$mailHeader = @imap_headerinfo($conn, $i);
$from = $mailHeader->fromaddress;
$subject = strip_tags($mailHeader->subject);
$date = $mailHeader->date;
echo "<tr> <td><font face='Arial' style='font-size: 9pt'>$from</font></td>
<td><font face='Arial' style='font-size: 9pt'>$subject</font></td>
<td><font face='Arial' style='font-size: 9pt'>$date</font></td>
</tr>" ;
}
imap_close($conn);
echo "</table>" ;
?>
This just shows the oldest first.
How can I fix it?
Thanks!