【问题标题】:displaying a message with imap_search based on a subject根据主题显示带有 imap_search 的消息
【发布时间】:2017-01-06 14:34:19
【问题描述】:

我正在尝试使用 imap_search 搜索“主题”和“UNSEEN”。它显示主题和名称,但不显示消息。

是否可以根据特定主题显示消息?

我的代码:

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

【问题讨论】:

  • 你需要显示一些代码。
  • 是的,对不起,我刚刚做了

标签: php imap


【解决方案1】:

一封电子邮件可以包含大量不同形式的数据,因此硬编码的2 将不起作用。有关详细信息,请参阅 HOW to get mail structure with part number using imap command,然后请注意您必须撤消 Content-Transfer-Encoding 等。

【讨论】:

  • 感谢您的回答,我遇到了看不见的消息的问题,我只是将消息标记为未读,这样不会起作用
【解决方案2】:

试试这个代码。它对我有用。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2020-10-27
  • 2023-04-04
  • 2013-10-07
  • 1970-01-01
  • 2015-07-13
  • 2011-01-11
  • 1970-01-01
  • 2020-03-18
相关资源
最近更新 更多