skip to Main Content

I use phpMailer for the processing of mail sent from the website. This morning I suddenly got the following message:

Fatal error: __autoload() is no longer supported, use spl_autoload_register() instead in C:xampphtdocswebappPHPMailerAutoload.php on line 45

I have PHP 8.0.0 running on the server

if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
    //SPL autoloading was introduced in PHP 5.1.2
    if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
        spl_autoload_register('PHPMailerAutoload', true, true);
    } else {
        spl_autoload_register('PHPMailerAutoload');
    }
} else {
    /**
     * Fall back to traditional autoload for old PHP versions
     * @param string $classname The name of the class to load
     */
    function __autoload($classname)
    {
        PHPMailerAutoload($classname);
    }
}

3

Answers


  1. You’re using a very old version of PHPMailer – that code has not been in PHPMailer for 3 years. PHP 8.0 is officially supported as of PHPMailer 6.2.0, and make sure you read the upgrade guide.

    Login or Signup to reply.
  2. Your issue will be resolved by changing
    function __autoload($classname) to function spl_autoload_register($classname)
    which has no adverse affect on the output.

    Login or Signup to reply.
  3. This is An Edited AutoLoad File in:
    PHPMailerPHPMailerAutoload.php

    function PHPMailerAutoload($classname)
    {
        //Can't use __DIR__ as it's only in PHP 5.3+
        $filename = dirname(__FILE__).DIRECTORY_SEPARATOR.'class.'.strtolower($classname).'.php';
        if (is_readable($filename)) {
            require $filename;
        }
    }
    
    if (version_compare(PHP_VERSION, '5.1.2', '>=')) {
        //SPL autoloading was introduced in PHP 5.1.2
        if (version_compare(PHP_VERSION, '5.3.0', '>=')) {
            spl_autoload_register('PHPMailerAutoload', true, true);
        } else {
            spl_autoload_register('PHPMailerAutoload');
        }
    } else {
        /**
         * Fall back to traditional autoload for old PHP versions
         * @param string $classname The name of the class to load
         */
        spl_autoload_register($classname);
        
    }
    

    Changes are done here:
    spl_autoload_register($classname);

    Thanks

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search