! ) Fatal error: Uncaught Error: Class 'PHPMailer' not found in G:\......\PHP\sendemail\public\index.php on line *15*
( ! ) Error: Class 'PHPMailer' not found in G:\......\PHP\sendemail\public\index.php on line *15*
The class PHPMailer is actually in the namespace PHPMailer\PHPMailer. If you omit that, then no, the autoloader can’t find it.
The correct syntax would be
<?php
require __DIR__ . '/vendor/autoload.php';
$mailer = new \PHPMailer\PHPMailer\PHPMailer();
However, since that’s rather longwinded, you can also use the use statement to indicate to PHP that each time you instance of a PHPMailer class, you actually mean PHPMailer\PHPMailer\PHPMailer.
<?php
use PHPMailer\PHPMailer\PHPMailer;
require __DIR__ . '/vendor/autoload.php';
$mailer = new PHPMailer();
// etc
The following link might also help even though it uses composer which I use as my auto loader is also very helpful. I know I was having a heck of a time with autoloaders, but a light bulb when on in my head after reading this page. https://phpenthusiast.com/blog/how-to-autoload-with-composer