我创建了一个系统,我抓住收件箱并将其显示在一个页面上。新收到的电子邮件自动出现。但现在我必须显示一个标记或不同的颜色,告诉用户这是新邮件。我怎样才能使用laravel 5。
这是我的控制器方法:
public function getMail()
{
/* connect to gmail */
$hostname = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'xyz@gmail.com';
$password = 'xyz';
/*Get all the data in $inbox*/
$inbox = imap_open($hostname, $username, $password) or die('Cannot connect: ' . imap_last_error());
/*collect ALL the messages in inbox*/
$emails = imap_search($inbox, 'ALL');
/*Collect unread messages only*/
$emails_unread = imap_search($inbox, 'UNSEEN');
/*Count rows from table 'Email'*/
$row_count = count(Email::all());
$email_count = count($emails);
$emails_unread_count = count($emails_unread);
/*For the first time when a new email is added*/
if($row_count == 0){
rsort($emails);
foreach($emails as $all_email){
$header = imap_headerinfo($inbox,$all_email);
$message = quoted_printable_decode (imap_fetchbody($inbox, $all_email, 1));
$from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
$toaddress = $header->toaddress;
$message_number = $header->Msgno;
Email::create(['from'=>$from, 'body'=>$message , 'message_no'=>$message_number]);
}
return $this->show();
}
/*when a new email gets added, compare stored email numbers with new email count */
elseif($row_count < $email_count){
rsort($emails_unread);
foreach($emails_unread as $unread){
$header = imap_headerinfo($inbox, $unread);
$message = quoted_printable_decode (imap_fetchbody($inbox, $unread, 1));
$from = $header->from[0]->mailbox . "@" . $header->from[0]->host;
$toaddress = $header->toaddress;
$message_number = $header->Msgno;
Email::create(['from'=>$from, 'body'=>$message , 'message_no'=>$message_number]);
}
return $this->show();
}
/*IF both above fails*/
else{
return $this->show();
}
imap_close($inbox);
}
答案 0 :(得分:0)
在Laravel中创建视图以显示此数据 Laravel - Views
将css文件添加到此视图,其中包含针对看不见的电子邮件的特定类