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条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作