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 https://stackoverflow.com/questions/44496171/phpmailer-gives-http-error-500-when-i-try-to-test-email-on-cloudways 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/xxx.cloudwaysapps.com/xxx/public_html/iframe/mailtest.php:3
thrown in /home/xxx.cloudwaysapps.com/xxx/public_html/iframe/mailtest.php on line 3
Something simple I’m missing?
I’ve boiled it down to the following tests:
<?php $to = "email@example.com"; $subject = "Testing"; $txt = "Hello world!"; mail($to,$subject,$txt,'From: firstname.lastname@example.org ','-f email@example.com '); ?>
This never gets past line 3:
<?php require_once "vendor/autoload.php"; //PHPMailer Object $mail = new PHPMailer; //From email address and name $mail->From = "firstname.lastname@example.org"; $mail->FromName = "Full Name"; //To address and name $mail->addAddress("email@example.com", "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.