Webklex / php-imap

PHP-IMAP is a wrapper for common IMAP communication without the need to have the php-imap module installed / enabled. The protocol is completely integrated and therefore supports IMAP IDLE operation and the "new" oAuth authentication process as well.
https://www.php-imap.com
MIT License
314 stars 146 forks source link

Simple code to move in INBOX folder not works... #528

Open Pok4 opened 5 days ago

Pok4 commented 5 days ago

Hello there, and sorry for my english.

I have this one:

        use Webklex\PHPIMAP\Client;
        use Webklex\PHPIMAP\Config;

        if (!empty(get_from_db_config('imap_server')) && 
            !empty(get_from_db_config('imap_email')) && 
            !empty(get_from_db_config('imap_pass'))) {

            $config = new Config([
                'username'      => get_from_db_config('imap_email'),
                'password'      => ''.get_from_db_config('imap_pass').'',
                'host'          => get_from_db_config('imap_server'),
                'port'          => 993,
                'encryption'    => 'ssl',
                'protocol'      => 'imap',
                'validate_cert' => true,
            ]);

            $oClient = new Client($config);

            $oClient->connect();

            $inbox = $oClient->getFolder('INBOX');

            $inbox->appendMessage($rawMessage); 

            $oClient->disconnect();
        }

i get the following error: Fatal error: Uncaught TypeError: Webklex\PHPIMAP\Client::setAccountConfig(): Argument #2 ($default_config) must be of type array, null given, called in C:\xampp2\htdocs\vendor\webklex\php-imap\src\Client.php on line 238 and defined in C:\xampp2\htdocs\vendor\webklex\php-imap\src\Client.php:258 Stack trace: #0 C:\xampp2\htdocs\vendor\webklex\php-imap\src\Client.php(238): Webklex\PHPIMAP\Client->setAccountConfig('host', NULL) #1 C:\xampp2\htdocs\vendor\webklex\php-imap\src\Client.php(189): Webklex\PHPIMAP\Client->setConfig(Object(Webklex\PHPIMAP\Config)) #2 C:\xampp2\htdocs\App\Models\Admin\View_Emails_Model.php(119): Webklex\PHPIMAP\Client->__construct(Object(Webklex\PHPIMAP\Config)) #3

i try many things with ChatGPT, including everything to be in Client([]), but same error... Im using last dev-master version. I dont know where i make a mistake..

Pok4 commented 5 days ago

i fixed it :) Here:

        use Webklex\PHPIMAP\ClientManager;
        //sent email to send folder
        if (!empty(get_from_db_config('imap_server')) && 
            !empty(get_from_db_config('imap_email')) && 
            !empty(get_from_db_config('imap_pass'))) {

            $cm = new ClientManager();  
            $client = $cm->make([
                'username'      => get_from_db_config('imap_email'),
                'password'      => ''.get_from_db_config('imap_pass').'',
                'host'          => get_from_db_config('imap_server'),
                'port'          => 993,
                'encryption'    => 'ssl',
                'protocol'      => 'imap',
                'validate_cert' => false,
            ]);

            $client->connect();

            $inbox = $client->getFolder(get_from_db_config('imap_folder') ?? 'Sent');

            $inbox->appendMessage($rawMessage);

            $client->disconnect();
        }