0

I feel like I am almost there. (I could be wrong though)

from the root of my apache server (/usr/local/var/www)

I ran

composer require phpmailer/phpmailer

I've now got the folder system

/usr/local/var/www/vendor/phpmailer/phpmailer

In this folder, there is a src folder, and in that folder are basically all the files I think I need to include on the php page where I want to use PHPmailer.

On the PHP page where I want to use PHPMailer, I have at the top:

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

and in the page I am calling

$mail = new PHPMailer(true); //Argument true in constructor enables exceptions

I am getting an error message

Error: Class "PHPMailer\PHPMailer\PHPMailer" not found in /usr/local/var/www/xxx.php

It seems like something isn't linking up correctly.

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80
  • 2
    You need to source composer's autoloader, typically via something like `require_once 'vendor/autoload.php';`. – Alex Howansky Jan 15 '22 at 00:48
  • Add the three lines: `require './Exception.php'; require './PHPMailer.php'; require './SMTP.php';` **after** the line `use PHPMailer\PHPMailer\Exception;` (change to the actual path for the 3 files please) , retry and see what happens – Ken Lee Jan 15 '22 at 02:06

1 Answers1

2

Alex Howansky posted a comment:

You need to source composer's autoloader, typically via something like require_once 'vendor/autoload.php';.

Ken Lee a comment:

Add the three lines: require './Exception.php'; require './PHPMailer.php'; require './SMTP.php'; after the line use PHPMailer\PHPMailer\Exception; (change to the actual path for the 3 files please) , retry and see what happens

Both suggestions fixed the problem. I'm going with the vendor/autoload.php solution.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
ControlAltDel
  • 33,923
  • 10
  • 53
  • 80