Reputation: 1087
I'm using the imap_search to get a list of messages from my INBOX. I want only the emails sent from the address, lets say "[email protected]".
I'm doing like:
$headers = imap_search($box,'FROM "[email protected]"', SE_UID);
But this takes so many time, around 3 minutes and the inbox have only 700 emails (my box is GMAIL). The problem is not from the server, because i installed roundcube in the localhost and loads the emails quickly.
What can i do to make it faster?
Upvotes: 4
Views: 2085
Reputation: 656
This method has worked faster than imap_search for me in the past:
$stream = imap_open($mailbox,$username,$password);
//imap_num_msg returns the number of messages in the current mailbox, as an integer, so ..
$total_messages = imap_num_msg($stream);
for ($message_number = 0; $message_number < $total_messages; $message_number++)
{
//get header
$header = imap_header($stream, $message_number);
if ($header === NULL)
continue;
//check from
if($header->from == '[email protected]')
{
// you found one so do something
}
}
Upvotes: 2