Search code examples
phpcomposer-phpphpmailerrequire

Class 'PHPMailer\PHPMailer\PHPMailer' not found in


I am using Composer, but nothing I have tried has worked.

I tried require composer autoload.

require BASE_URL.'assets/vendor/autoload.php';

and use the namespace

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

but I still receiving a Error message

Fatal error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in

Here is my simplified class

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'vendor/phpmailer/src/Exception.php';
require 'vendor/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/src/SMTP.php';
class Email extends model{ 
    public function enviarContato($nome, $email, $mensagem){
        $mail = new PHPMailer(true); 
}
}

I believe that i am importing wrong, so here is my path structure.

img

img

I'm using Email.php.

Thanks


Solution

  • BASE_URL contain http://192.168.1.240/project/

    If you feed require with a URL the whole call happens through the web server, thus you get the result of code execution rather than code itself. You need a file system path, e.g.:

    require __DIR__ . '/path/to/autoload.php';