barbushin / php-imap

Manage mailboxes, filter/get/delete emails in PHP (supports IMAP/POP3/NNTP)
MIT License
1.66k stars 459 forks source link

Mail search failed UID SEARCH State error #575

Open thesky2017 opened 3 years ago

thesky2017 commented 3 years ago

PHP IMAP version: IMAP c-Client Version => 2007f SSL Support => enabled Kerberos Support => enabled

PHP Version: 5.6 Type of execution: cli

Get 163 is an error, the error message is: IMAP method IMAP_ search() failed with error: UID SEARCH State error code: $mailbox = new \PhpImap\Mailbox('{imap.163. com:993/imap/ssl }INBOX', ' xxxxx@163.com ', 'xxx',$dir);

$mailsIds = $mailbox->searchMailbox('RECENT');

What is the reason?think you.

Sebbo94BY commented 3 years ago

Please always use the try-catch method:

$mailbox = new PhpImap\Mailbox(
    '{imap.163. com:993/imap/ssl}INBOX', // IMAP server and mailbox folder
    'xxxxx@163.com', // Username for the before configured mailbox
    '*********' // Password for the before configured username
);

try {
    // Search in mailbox folder for specific emails
    // PHP.net imap_search criteria: http://php.net/manual/en/function.imap-search.php
    // Here, we search for "all" emails
    $mails_ids = $mailbox->searchMailbox('ALL');
} catch(PhpImap\Exceptions\ConnectionException $ex) {
    echo "IMAP connection failed: " . $ex;
    die();
}

Also try the search criteria ALL first, to see if the connection is even working or not.

Your error usually means, that it can not connect to the mailbox, because the folder does not exist for example.

FancyFunction commented 3 years ago

I also have a similiar error: IMAP method imap_search() failed with error: Unknown search criterion: UID in /mnt/web303/d1/56/54153156/htdocs/Christian/project002/debug/vendor/php-imap/php-imap/src/PhpImap/Imap.php:1106 Stack trace: #0 /mnt/web303/d1/56/54153156/htdocs/Christian/project002/debug/vendor/php-imap/php-imap/src/PhpImap/Imap.php(849)

Searching with 'All' works as expected. Neither of the following works: 'UID 0:*', '0:*', 0, *

NeilVicente commented 2 years ago

I also have a similiar error: IMAP method imap_search() failed with error: Unknown search criterion: UID in /mnt/web303/d1/56/54153156/htdocs/Christian/project002/debug/vendor/php-imap/php-imap/src/PhpImap/Imap.php:1106 Stack trace: #0 /mnt/web303/d1/56/54153156/htdocs/Christian/project002/debug/vendor/php-imap/php-imap/src/PhpImap/Imap.php(849)

Searching with 'All' works as expected. Neither of the following works: 'UID 0:*', '0:*', 0, *

I don't think UID is a valid criterion for imap_search

You can find the list of valid criteria here.