开发者

How to search in e-mail's body with PHP?

I wondered how can I search for a particular word in all inbox e-mails with PHP IMAP? This search might be a regexp performed over the mess开发者_如何学Pythonage's body...


I would do the following..

Connect to the the inbox:

$imap_stream = imap_open($host,$username,$pass);
$imap_obj = imap_check($imap_stream);
$numMsgs = $imap_obj->Nmsgs;

Check out the docs for the format of $host etc.

Loop around each message:

while ($mailNumber<= $numMsgs) {
  $message  = imap_fetchbody ($imap_stream,$mailNumber,1);

  //Regex each message:
  if(preg_match($pattern, $string){
         imap_mail ($to,$subject,$message);
  }
}

EDIT

If you want forward a specific email, you could use imap_mail() to send it on. See above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜