Class PHPMailer not found

I started with the blog post here, because I need to send attachments:

I’ve also followed the instructions and created the sample shown in the first answer at and have already run composer: composer require phpmailer/phpmailer in the directory.
The key lines of the file being:

<?php require_once "vendor/autoload.php"; //PHPMailer Object $mail = new PHPMailer; //From email address and name ...

I still get the following error each time:

PHP Fatal error: Uncaught Error: Class ‘PHPMailer’ not found in /home/
Stack trace:
#0 {main}
thrown in /home/ on line 3

Something simple I’m missing?

I’ve boiled it down to the following tests:

This works:

<?php $to = ""; $subject = "Testing"; $txt = "Hello world!"; mail($to,$subject,$txt,'From: ','-f '); ?>

This never gets past line 3:

<?php require_once "vendor/autoload.php"; //PHPMailer Object $mail = new PHPMailer; //From email address and name $mail->From = ""; $mail->FromName = "Full Name"; //To address and name $mail->addAddress("", "Recepient Name");//Recipient name is optional $mail->isHTML(true); $mail->Subject = "Subject Text"; $mail->Body = "Mail body in HTML"; $mail->AltBody = "This is the plain text version of the email content"; //Enable SMTP debugging. $mail->SMTPDebug = 3; //Set PHPMailer to use SMTP. $mail->isSMTP(); //Set SMTP host name ... etc with credentials

Again, I’ve run composer in this directory. Output is:

iframe$ composer require phpmailer/phpmailer
Using version ^6.0 for phpmailer/phpmailer
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files

Thanks for your help.

Hi Eballer,
I hope you are doing good.

PHPmailer has the latest version now which is 6.x. This version is not using autoload.php file.

After installing PHPmailer library to your project you need to add exact path of the files in your code.
The files are installed in vendor folder similar like other packages.

Below is the example:


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

require 'vendor/phpmailer/phpmailer/src/Exception.php';
require 'vendor/phpmailer/phpmailer/src/PHPMailer.php';
require 'vendor/phpmailer/phpmailer/src/SMTP.php';

$mail = new PHPMailer();

Rest code is same you can try now to send email. Let me know if any problem arise again.


That was it, thank you! Any way to get in touch with cloudways developers to have them update the blog entry that their support team points to?

1 Like

Hi, Glad to know this works now. You can ask me about any feedback. I’ll take care of the blog update don’t worry.

It would be nice to have that blog post updated. Spent almost a day trying to figure this out until I found this post.

Thank you