Search code examples
phplaravelimap

laravel imap class not found, install is good


I'm using the Weblex laravel IMAP package and after installing, publishing, etc. I can't run a test script because it won't find the class

I've followed the install and setup instructions exactly. Running this on laravel 5.8 by the way

composer require webklex/laravel-imap

php artisan vendor:publish --provider="Webklex\IMAP\Providers\LaravelServiceProvider"

I've created a file in my root directory (in testproject, so it's at the same level as App and Public) called mailtest.php but I can't get it to find the actual class.

I've tried this:


$oClient = \Webklex\IMAP\Facades\Client::account('default');
$oClient->connect();

and this:

<?php
use \Webklex\IMAP\Client;

$oClient = new Client([
    'host'          => 'somehost.com',
    'port'          => 993,
    'encryption'    => 'ssl',
    'validate_cert' => true,
    'username'      => 'username',
    'password'      => 'password',
    'protocol'      => 'imap'
]);

$oClient->connect();

but when running php mailtest.php in my root folder via CLI I get:

Fatal error: Uncaught Error: Class 'Webklex\IMAP\Facades\Client' not found in /Users/testUser/Websites/task-manager/mailtest.php:3

What am I doing wrong?


Solution

  • You shouldn’t run a php file directly from cli and expect it to work you are just running a php file without loading vendor files ( composer) you could try

    <?php 
    
    include __DIR__.'/vendor/autoload.php';
    

    But I’m not sure if it will work if you are using laravel you can create new command and run it from php artisan command