douxi3977 2016-07-11 07:35
浏览 86
已采纳

使用基于主题的imap_search显示消息

I am trying to search with "subject" and "UNSEEN" using imap_search. It displays the subject and the name but not the message.

Is it possible to display the message based on a specific subject ?

my code :

set_time_limit(4000);

$imapPath = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'slimanii.leila@gmail.com';
$password = '*****';

$inbox = imap_open($imapPath,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error());

$emails = imap_search($inbox,'UNSEEN SUBJECT "aaa"');

$output = '';

if($emails) {
$output = '';
rsort($emails);
foreach($emails as $email_number) {
    $overview = imap_fetch_overview($inbox,$email_number,0);
    $message = imap_fetchbody($inbox,$email_number,2);
    $output.= '<div class="toggler '.($overview[0]->seen ? 'read' : 'unread').'">';
    $output.= '<span class="subject">'.$overview[0]->subject.'</span> ';
    $output.= '<span class="from">'.$overview[0]->from.'</span>';
    $output.= '<span class="date">on '.$overview[0]->date.'</span>';
    $output.= '</div>';
    $output.= '<div class="body">'.$message.'</div>';
}

echo $output;
} 
imap_expunge($inbox);
imap_close($inbox);
  • 写回答

2条回答 默认 最新

  • dongyou26216708 2016-07-20 11:06
    关注

    An e-mail message can contain a lot of data in various forms, so a hardcoded 2 won't work. See HOW to get mail structure with part number using imap command for details, then note that you'll have to undo Content-Transfer-Encoding, etc.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 自适应 LMS 算法实现 FIR 最佳维纳滤波器matlab方案
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥15 Python3.5 相关代码写作
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像