开发者

Problem with imap_fetchstructure(): Bad message number

I'm working on IMAP readi开发者_如何转开发ng email from mine google account, and can't find a way to check is email with exact number exists or why this errors happens.

Here is my code, so basically I make an connection than search all email go get list of them which are from specific sender list, and then run process function

$mail_conn = imap_open($this->hostname, $this->username, $this->password);

...

$emails = imap_search($mail_conn, 'FROM ' . $sender, SE_UID);
$results = $this->process($mail_conn, $emails);

Process function looks like this

....

            foreach ($emails as $email_number)
            {
            $email_structure = imap_fetchstructure($mail_conn, $email_number, FT_UID);

.....

I tried to remove FT_UID but same error persists. What could be your suggestion what to do?

What I get when I debug is:

In emails imap_search returns

[emails] => Array
    (
        [0] => 513384
        [1] => 513501
        [2] => 514079
    )

I start process this id

[email_number] => 513384

after that error occurs.


I'm experiencing same problem and following seem to help:

Replace your search call

$emails = imap_search($mail_conn, 'FROM ' . $sender, SE_UID);

with sort call with search criteria

$emails = imap_sort($mail_conn, SORTARRIVAL, 0, null, 'FROM ' . $sender);

Note that if option SE_UID is specified (instead of null which i have there) it stops working for some reason...


Function imap_sort have format:

imap_sort ($imap_stream, $criteria, $reverse, $options = 0, $search_criteria = null, $charset = 'NIL')

You must be use: imap_sort ($mail_conn, SORTARRIVAL, 0, SE_UID, 'FROM ' . $sender)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜