Support

Akeeba Backup for WordPress

#42617 class-phpmailer.php

Posted in ‘Akeeba Backup for WordPress’
This is a public ticket

Everybody will be able to see its contents. Do not include usernames, passwords or any other sensitive information.

Environment Information

WordPress version
6.9
PHP version
8.3
Akeeba Backup version
9.1.1

Latest post by nicholas on Tuesday, 13 January 2026 00:46 CST

riccardopreviti

Hi, I'm using Query Monitor to monitor some activity on my site and I found a warning/error related to Akeeba.

Caller: 

  1. AkeebaBackupWP::loadAkeebaBackupContainer()

The class-phpmailer.php file is deprecated since version 5.5.0! Use wp-includes/PHPMailer/PHPMailer.php instead. The PHPMailer class has been moved to wp-includes/PHPMailer subdirectory and now uses the PHPMailer\PHPMailer namespace.

Why?

nicholas
Akeeba Staff
Manager

I had explained that when we made that release, and I have explained it in great detail in the code comment in wp-content/plugins/akeebabackupwp/helpers/integration.php which would be where you'd look if you followed the PHP notice (not an error or even a warning):

/**
* Some folks who don't understand how PHP works try to load WordPress' PHPMailer by doing a require_once either on
* the legacy shim (wp-includes/class-phpmailer.php), or on the modern class files
* (wp-includes/PHPMailer/PHPMailer.php and wp-includes/PHPMailer/Exception.php) WITHOUT wrapping them in
* class_exists() check.
*
* This is problematic for many reasons:
* - If another plugin (or the core) has loaded the OTHER kind of files, the require_once check will try to load the
* same class twice, breaking the execution environment.
* - If another plugin has registered an autoloader with a different copy of PHPMailer, like we do, and a second 3PD
* plugin tried to use PHPMailer using a class_exists() check without setting the second parameter to false, they
* will try to load WordPress' copy of PHPMailer under the same namespace, breaking the execution environment.
*
* The CORRECT solution is the standard class_exists() safety check which has been common knowledge since the early
* 2000s:
*
* if (!class_exists(PHPMailer\PHPMailer\PHPMailer::class, false)) {
* require_once ABSPATH . WPINC . '/class-phpmailer.php';
* }
*
* The require_once MUST NOT BE USED as a code safety feature against double definition attempt of a class or f
* unction. Code safety requires using class_exists() and function_exists().
*
* Some folks, like ThemeCatcher (makers of QuForm), apparently are strangers to decades-old PHP code safety standards
* and will publish support pages accusing us for their own shitty code without having the decency to contact us
* first.
*
* We can't fix stupid, but we CAN and DO work around it. The simple way we chose to deal with this particular brand
* of stupid is by including WordPress' PHPMailer class before including our own autoloader. This means that you now
* have WordPress' files loading PHPMailer in the require_once/include_once cache, so even when morons like those
* people rely on this mechanism for code safety they won't manage to shoot their feet. Since the PHPMailer class is
* loaded, our Composer autoloader won't even try to load our copy of PHPMailer UNLESS we are running outside of
* WordPress, i.e. our CLI backup script which is why we have a copy of PHPMailer to begin with.
*
* The code is backward- and forward-compatible:
* - On WordPress <= 5.4 it loads wp-includes/class-phpmailer.php which registers the legacy, non-namespaced PHPMailer
* class. On these versions of WordPress, our Composer autoloader WILL load our newer, namespaced version of
* PHPMailer without breaking core WordPress or 3PD plugins.
* - On WordPress >= 5.5 it loads wp-includes/class-phpmailer.php which registers the new, namespaced PHPMailer class.
* On those versions of WordPress, our Composer autoloader WILL NOT load our copy of PHPMailer. Plugins loading
* directly either this legacy shim, or the modern class files, will NOT break.
* - On future WordPress versions removing the legacy shim, the modern class files are included. On those versions of
* WordPress, again, our Composer autoloader WILL NOT load our copy of PHPMailer. Plugins loading directly the
* legacy shim WILL fail because that (future) versions of WordPress does not include the shim. Plugins loading
* directly the modern class files WILL NOT break.
*/

Nicholas K. Dionysopoulos

Lead Developer and Director

🇬🇷Greek: native 🇬🇧English: excellent 🇫🇷French: basic • 🕐 My time zone is Europe / Athens
Please keep in mind my timezone and cultural differences when reading my replies. Thank you!

Support Information

Working hours: We are open Monday to Friday, 9am to 7pm Cyprus timezone (EET / EEST). Support is provided by the same developers writing the software, all of which live in Europe. You can still file tickets outside of our working hours, but we cannot respond to them until we're back at the office.

Support policy: We would like to kindly inform you that when using our support you have already agreed to the Support Policy which is part of our Terms of Service. Thank you for your understanding and for helping us help you!