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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.