我来的时候整理mij邮件有点麻烦,
我有这个密码来收到我的邮件:
$mailbox = new ImapMailbox($hostname,$row["user_email"],$row["user_mail_password"])
/* Count mails in $mbox */
$mail_count = $mailbox->countMails();
/* put the newest emails on top */
$mails_sort = $mailbox->sortMails();
var_dump($mails_sort);
/* overview mails in $mbox */
$mailsIds = $mailbox->searchMailBox('ALL');
var_dump($mailsIds);
/* get data of mails */
$mails = $mailbox->getMailsInfo($mails_sort);
/* for every email... */
foreach ($mails as $mail) {
/* Put date result at DateTime constructor*/
$message_date=new DateTime($mail->date);
/* output the email header information */
$output.= '<tr class="'.($mail->seen ? 'read' : 'unread').'">';
$output.= '<td class="small-col"><input type="checkbox" /></td>';
$output.= '<td class="small-col"><i class="clickable fa fa-'.($mail->flagged ? 'star' : 'star-o').'"></i></td>';
$output.= '<td class="name"><a href="?page=read-mail&folder='.$mbox.'&uid=' . $mail->uid . '" >' . $mail->from . '</a></td>';
$output.= '<td class="subject"><a href="?page=read-mail&folder='.$mbox.'&uid=' . $mail->uid . '" >' . $mail->subject . '</a></td>';
$output.= '<td class="time">'.$message_date->format("d-m-Y H:i").'</td>';
$output.= '</tr>';
}当我运行我的邮件从旧到新显示的代码时,我想从新到旧显示,
我使用的imap类来自:https://github.com/barbushin/php-imap
有一个功能:
public function sortMails($criteria = SORTARRIVAL, $reverse = true) {
return imap_sort($this->getImapStream(), $criteria, $reverse, SE_UID);
}来自:$mails_sort的输出是正确的输出,所有UID都是从新到旧的。
$mailsIds的输出是UID从旧到新的输出。
但是它不能按照正确的顺序显示我的邮件,我想我在这里漏掉了一些东西。
发布于 2015-05-02 12:55:36
只需在foreach循环rsort($mails)之前使用一行;
$inbox = imap_open($hostname,$username,$password,NULL,1)或死(“无法连接到邮件服务器:”)。Print_r(imap_errors());/*抓取邮件*/
$mails = imap_search($inbox,'ALL'); // UNSEEN = for unread mail, SEEN = READ mail , ALL = all mail READ as well as UNREAD mail
/* if emails are returned, cycle through each... */
rsort($mails);
foreach($mails as $key => $value) {
// body
}https://stackoverflow.com/questions/27336152
复制相似问题