Skip to content
Advertisement

Error: Class ‘PHPMailer’ not found

Error: Fatal error: Uncaught Error: Class ‘PHPMailer’ not found in C:xampphtdocsphp-mailerindex.php:4 Stack trace: #0 {main} thrown in C:xampphtdocsphp-mailerindex.php on line 4

My PHP Code here:

JavaScript

Please let me know what mistake I made here in my code.

Advertisement

Answer

It’s because you’ve not considered PHPMailer’s namespace. Do one of these two things:

Change your instantiation to use a fully-qualified class name (FQCN):

JavaScript

Alternatively, define the import at the top of your file, before you load the classes:

JavaScript

This will allow your existing new PHPMailer line to work.

All the examples provided with PHPMailer use the latter approach, and it’s also described in the troubleshooting guide.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement