0

Exact error being given:Error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in C:\wamp64\www\tutoring\web\environment.php on line 37

My code:

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

require __DIR__ . '../vendor/autoload.php';

Line 37:

// This is inside of a function but the uses and require are not
$mail = new PHPMailer;

My file tree:

vendor folder and environment.php both in web folder

autoload is in the right place and so is the PHPMailer class:

autoload is in the right place and so is the PHPMailer class

I've been trying to fix this for the past 2 hours. Every post I've seen with this issue has been resolved with something that doesn't fix mine.

Synchro
  • 35,538
  • 15
  • 81
  • 104
lbertoni
  • 11
  • 1
  • Have you rebuilt the autoloader since adding the PHPMailer library? Did you try putting the `require` line before the `use` lines? I'm not sure if the order matters, but if it does then it's almost certain that the order you have would be the wrong one. – Greg Schmidt May 01 '20 at 01:37
  • Try `require_once __DIR__ . '/../vendor/autoload.php';`. Note the `/` before `..` – Phil May 01 '20 at 06:47
  • @GregSchmidt the `use` statements should definitely come first – Phil May 01 '20 at 06:49
  • That's weird, because I use a framework where the autoloader is included long before any `use` statements happen. – Greg Schmidt May 01 '20 at 15:32

1 Answers1

-1

Have you include/require phpmailerautoload.php?,

This works for me,

require_once('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer();
Erwin_San
  • 21
  • 6
  • It just says it failed to open stream. I also tried require_once('../vendor/PHPMailer/PHPMailerAutoload.php'); which also failed to open stream. – lbertoni May 01 '20 at 02:00
  • check your path manually and check your included path , is there a typo or someting ? my email.php is located beside PHPMailer folder, and there is directly PHPMailerAutoload.php in PHPMailer folder – Erwin_San May 01 '20 at 02:07
  • If your code says that, you're using a very old version of PHPMailer and should upgrade. – Synchro May 01 '20 at 06:38