Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Pok4 opened this issue Oct 30, 2024 · 1 comment
Open

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

Pok4 opened this issue Oct 30, 2024 · 1 comment

Comments

@Pok4
Copy link

Pok4 commented Oct 30, 2024

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
Copy link
Author

Pok4 commented Oct 30, 2024

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();
		}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant