MailPoet Fatal: Class “DOMDocument” not found – How to Fix (PHP‑XML/DOM)

If MailPoet breaks with Fatal error: Uncaught Error: Class 'DOMDocument' not found, your server is missing the PHP DOM extension (bundled in php-xml on most distros). MailPoet (and libraries it uses) rely on DOMDocument to parse HTML and templates. Here’s the quickest way to enable it, plus ways to verify the fix for both web (PHP‑FPM/Apache) and CLI.

MailPoet crashes with “Class ‘DOMDocument’ not found” after a host/PHP upgrade. How do I fix this without disabling MailPoet?

This error means PHP’s DOM extension isn’t loaded for the PHP runtime your site is using. Enable/install it, then restart PHP and verify. Steps below cover common setups.

1) Confirm the problem (web vs CLI)

  • From the web runtime (PHP‑FPM/Apache): temporarily create phpinfo.php in your site root:
    <?php phpinfo(); ?>

    Load https://yoursite.com/phpinfo.php and search for “DOM”.
    Important: delete this file after testing.

  • From the shell (CLI):
    php -m | grep -i dom

    If it prints “dom”, the CLI has it; if your site still errors, the web PHP (php-fpm/Apache) is missing it or using a different php.ini.

2) Enable/install the DOM (php-xml) extension

cPanel (Select PHP Version)

  1. In cPanel, open Select PHP Version (or “PHP Selector”).
  2. Switch to the same PHP version your site uses.
  3. Tick dom (and typically xml, xmlreader, xmlwriter are bundled).
  4. Save/Apply; then restart PHP if your host exposes that option.

Ubuntu/Debian

sudo apt-get update
# If your PHP is 8.2, use php8.2-xml; for distro default, php-xml is fine
sudo apt-get install -y php-xml php8.2-xml
# Restart the handler your site uses:
sudo systemctl restart php8.2-fpm || sudo systemctl restart apache2

RHEL/CentOS/Alma/Rocky

sudo dnf install -y php-xml
sudo systemctl restart php-fpm || sudo systemctl restart httpd

Plesk

  1. Tools & Settings → PHP Settings for your PHP version, ensure the dom/xml extension is enabled; or install via Tools & Settings → Updates → Add/Remove Components.
  2. Restart PHP‑FPM for that domain.

Windows / Local PHP

  1. Edit php.ini and ensure the line extension=dom (or extension=php_dom.dll on older PHP) is not commented.
  2. Restart Apache/Nginx/PHP‑FPM.

3) Verify it’s fixed

  • Reload your phpinfo.php page and confirm the DOM section exists.
  • Clear OPcache / server cache if enabled, then retest MailPoet.

4) If errors persist

  • Different PHP for web vs CLI: Your shell might be using a different PHP binary. Compare outputs:
    which php
    php -i | grep "Loaded Configuration File"
    # Create a temporary file in WP root and load it in the browser:
    # <?php phpinfo(); ?>  # Check "Loaded Configuration File" there too.

    Make sure both environments load a php.ini that enables DOM.

  • Hosting support: Ask your host to enable php-xml for your exact PHP version (e.g., 8.2) on the web runtime.
  • Keep PHP modern: Don’t downgrade PHP; this is a missing extension, not a version bug.

Why this works

DOMDocument is part of PHP’s DOM extension. Without it, any plugin that parses HTML/XML (MailPoet templates, inline CSS, etc.) will fatal as soon as it tries to instantiate new DOMDocument(). Installing/enabling php-xml loads DOM and resolves the crash.


Need help confirming the right PHP handler or enabling the module in your hosting panel? We can check your phpinfo and set this up for you.

Need human WordPress help?

WP Assistant is a free tool created by Atiba Software, a WordPress design and development company located in Nashville, TN. If you need more personalized WordPress assistance let us know, and we’ll get back to you ASAP!