I am trying to fetch email using imap function which return very old email. Following script i am trying
$imap = @imap_open("{mail.******.com:143/novalidate-cert}", $sEmail, $sPwd);
$message_count = @imap_num_msg($imap);
for ($m = 1; $m <= $message_count; ++$m){
$header = @imap_rfc822_parse_headers(imap_fetchheader($imap, $m));
$email[$m]['from'] = $header->from[0]->mailbox.'@'.$header->from[0]->host;
}
Currently above function return email in ascending order, so that's why very old emails (2015's Email) are coming first. So is there any way to get recent email first.
for ($m = 1; $m <= $message_count; ++$m)- reverse this.$min each iteration?for ($m = 1; $m <= $message_count; ++$m), you start by setting$mto1; then, if it's below$message_count, you increment it (++$m).forloop is hard? Okay, look at this answer - the first option they use there: stackoverflow.com/a/2089282/19746