简体   繁体   中英

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

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, eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM