0

I am troubleshooting a code I inherited, and code that includes PHPMailer stopped working earlier this week. Here is a stripped-down code version with echo statements inserted to see where it fails.

<?php

echo '<p>First Debug line<br></p>';

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

echo '<p>after use<br></p>';

require 'vendor/autoload.php';

echo '<p>after vendor/autoload.php<br></p>';

$mail = new PHPMailer(true);

echo '<p>After PHPMailer<br></p>'; // this statement does not get executred

REV 1. Added following error trapping and I get the following now. What is puzzling to me that it was working a couple of days ago...

First Debug line

after use

after vendor/autoload.php

Fatal error: Uncaught Error: Class 'PHPMailer\PHPMailer\PHPMailer' not found in...

<?php

ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);

echo '<p>First Debug line<br></p>';

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

echo '<p>after use<br></p>';

require 'vendor/autoload.php';

echo '<p>after vendor/autoload.php<br></p>';

$mail = new PHPMailer(true);

echo '<p>After PHPMailer<br></p>';
  • 2
    Is error reporting enabled? What changed earlier in the week, PHP update/downgrade? – user3783243 Jun 10 '22 at 15:24
  • Not sure... How can I tell if it is? As I said - this is an application that I inherited. – Egils Robs Jun 10 '22 at 15:26
  • please post the error for better identify the issue – Kiran Maniya Jun 10 '22 at 15:28
  • The webpage does not show any errors. It displays the echo statements, but nothing else seems to be failing as far as I can tell – Egils Robs Jun 10 '22 at 15:30
  • See https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display sounds like you do not have error reporting enabled. – user3783243 Jun 10 '22 at 15:30
  • @EgilsRobs add `ini_set("error_reporting", -1)` and `display_errors(true)` to the top of your script. – Code Spirit Jun 10 '22 at 15:37
  • If you are using Gmail, they recently disabled `less-secure-apps`, which might be the reason your PHPMailer is not working. You will have to use an `app password` instead. Checkout this url: https://support.google.com/accounts/answer/6010255?hl=en#zippy=%2Cuse-an-app-password – Hef Jun 10 '22 at 15:42
  • Fatal errors will appear in your web servers error log. The gmail change was a good guess this week, but it's not getting to the point where that would explain it. – Synchro Jun 10 '22 at 15:56

0 Answers0