Jump to content

imap_search


beidlerj

Recommended Posts

Hello,

 

I am having trouble getting any results back from the imap_search function.  I assume it has to do with getting the right query string.

 

I am grabbing a string of keywords from an HTML form input box, and (trying to) search the IMAP inbox for messages which contain the $keywords string in either the BODY or the SUBJECT.  Can anyone lend some help with the correct string to send to the server?  I keep getting nothing back, meaning that the server doesn't understand the query.

 

$link = imap_open($server, $UN, $PW) or die(imap_last_error());

$matches = imap_search($link, "BODY \"$keywords\" SUBJECT \"$keywords\"");

if ($matches === false)
{
   echo "Server didn't understand query.<p>";
   echo imap_last_error();
}

 

Thanks,

 

Jeff

 

Link to comment
https://forums.phpfreaks.com/topic/59848-imap_search/
Share on other sites

If I only try this code:

 

$matches = imap_search($link, "SUBJECT \"$keywords\"");

 

I get an array of msg IDs that matched.  However, when I try this code:

 

$matches = imap_search($link, "BODY \"$keywords\"");

 

...then the function returns false.  Is this a problem with the implementation, or is there some other "magic phrasing" I need to use, in order to search the body of messages for a keyword?

Link to comment
https://forums.phpfreaks.com/topic/59848-imap_search/#findComment-299583
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.