Reply To: Compatibility issue with PHPMailer – Akeeba is guilty of writing safe code

Home Forums Quform WordPress Compatibility issue with PHPMailer – Akeeba is guilty of writing safe code Reply To: Compatibility issue with PHPMailer – Akeeba is guilty of writing safe code

#37826
Dirk
Participant

Hi Ally,

Thanks again for the update and for taking the time to debug this.

I just wanted to clarify one important detail regarding the test you ran:

The fatal error you encountered — Cannot declare class PHPMailer\PHPMailer\PHPMailer, because the name is already in use — happens **because the Composer autoloader (triggered by instantiating PHPMailer)** loads the class *before* WordPress tries to load its legacy shim via wp_mail(). So when WordPress then includes /wp-includes/PHPMailer/PHPMailer.php, it attempts to re-declare the class, which PHP rightfully blocks.

This is not caused by Akeeba doing something wrong — it’s actually behaving exactly as expected for a Composer-loaded class.

### 💡 The root of the issue:
To avoid this conflict, the following pattern should be used:

if (!class_exists('\\PHPMailer\\PHPMailer\\PHPMailer', false)) {
    require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
    require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
}

Also important:
This issue is not limited to Akeeba Backup Pro. It also happens with the free version of Akeeba Backup, which is publicly available on the akeeba Website. So anyone running the free version will also experience the same AJAX error when using QuForm. 😉

Just having Akeeba Backup active — no matter the edition — is enough to trigger the problem due to the way PHPMailer gets loaded. So it’s definitely reproducible without needing a commercial license!

So please grab yourself a copy of Akeeba Free Version and test it!

Thank you in advance!

Be inspired. © 2025 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy