0

I recently installed PHPMailer and right off the bat I am getting this error:

Uncaught Error: Class PHPMailer not found in /var/www/mydomain/send-email.php

I originally included the PHPMailer code like this:

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

When that did not work, I tried this because this is where the files for PHPMailer are:

include('/usr/share/php/libphp-phpmailer/src/PHPMailer.php');
include('/usr/share/php/libphp-phpmailer/src/Exception.php');

Same error, what am I doing wrong here?

ADyson
  • 57,178
  • 14
  • 51
  • 63
user979331
  • 11,039
  • 73
  • 223
  • 418
  • 2
    You need to do both. `include` and `use` do two different things (you can read about them both in the PHP documentation, and no doubt in many other places too). `require` loads the files from disk, and `use` brings the mentioned namespace into the current scope (so it's conceptual rather than a file operation). It's not clear why you're mucking about trying to guess or work this out yourself though, since PHPMailer published a very handy guide right there on their front page showing you which statements you need: https://github.com/PHPMailer/PHPMailer#installation--loading – ADyson Jul 14 '23 at 14:21
  • @ADyson ADyson is correct and should post his/her comment as an actual answer. Maybe the new answer could be edited with a link to the PHP documentation for `include` and `use` to help people reach the correct ressource faster. – XceeD Jul 14 '23 at 14:36
  • 3
    @XceeD if anything it should be marked as a duplicate of https://stackoverflow.com/questions/28906487/fatal-error-class-phpmailer-not-found where there are already answers for this error covering several versions of PHPMailer. But really I was just curious why the OP didn't simply read the PHPMailer instructions directly. – ADyson Jul 14 '23 at 14:38

0 Answers0