php mailer 5.2.23 Installation via composer

php mailer 5.2.23 Installation via composer

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

PHPMailer 5.2.23 Installation via Composer: A Practical Guide

Integrating PHPMailer version 5.2.23 into a modern PHP environment often trips developers who attempt to mix legacy file structures with modern dependency managers. The source material outlines a specific workflow involving manual directory creation, uploading raw files, and then invoking composer update on the project's root composer.json. While this approach technically allows Composer to manage dependencies, it introduces significant friction that can lead to runtime errors like Class 'League\OAuth2\Client\Provider\Google' not found.

The core issue lies in how Composer resolves autoloaded classes when the library is installed via directory upload rather than a standard package installation. When you manually create a directory like PHPMailer-5_2_23 and upload the zip contents, the file structure often lacks the necessary vendor directory generated by Composer's autoloader. Running composer update on a local copy of the GitHub repository is valid for updating dependencies within that project, but it does not automatically populate the autoloader for classes residing in your project root unless they are explicitly included in the autoload or classmap definitions.

The JSON configuration provided shows a classmap autoload entry pointing directly to specific files like class.phpmailer.php. This works fine if those files exist in the current working directory when Composer runs. However, the fatal error regarding the Google OAuth provider suggests that the league/oauth2-google package was added, but its classes are not being discovered by the PSR-4 or classmap autoloader.

To resolve this without manually editing composer.json every time, you should ensure the library is treated as a dependency rather than a project root file. If you strictly need version 5.2.23 for legacy compatibility reasons, the most robust method is to add it directly to your composer.json under the require section:

"require": {
    "phpmailer/phpmailer": "5.2.23",
    "league/oauth2-google": "^3.0" // Check version compatibility for 5.2.23 era
}

After defining this, running composer install or composer update will generate the necessary vendor directory and update the autoload.php file to correctly map the League\OAuth2\Client namespace. This eliminates the need to manually upload files into a public_html subdirectory and then try to make Composer "see" them.

Handling Legacy Class Structures

PHPMailer 5.2.23 relies heavily on class maps rather than PSR-4 namespaces for its core classes. The composer.json snippet in the source material lists specific file paths under autoload.classmap. If you are deploying to a shared hosting environment where you create a folder named public_html/PHPMailer-5_2_23, you must ensure that the files referenced in the class map (like class.smtp.php) are actually present in that directory relative to where Composer expects them.

A common pitfall is adding the OAuth provider via command line (composer require league/oauth2-google) without verifying that the version of the library supports the expected OAuth2 client interface. The error Class 'League\OAuth2\Client\Provider\Google' not found typically indicates a mismatch between the installed OAuth2 client library and the PHPMailer version, or simply that the autoloader hasn't been recompiled after adding the new package.

Best Practices for Deployment

Instead of the "upload then update" workflow described in the source material, which risks leaving your application in an inconsistent state where some files are version-controlled by Git (or uploaded) and others are managed by Composer, consider these alternatives:

  1. Vendorize the Library: Add phpmailer/phpmailer to your project's composer.json. Run composer update, and then copy the contents of vendor/phpmailer/ into your project directory if you need a monolithic structure. This ensures the autoloader is generated correctly before you move files around.
  2. Use Namespaces: If possible, migrate to a version of PHPMailer that fully supports PSR-4. This allows Composer to handle all class mapping automatically without needing a manual classmap.
  3. Verify Autoloaders: After adding any new package like league/oauth2-google, always clear your cache and run composer dump-autoload before testing the OAuth token retrieval script.

The workflow of uploading files manually and then running Composer commands is technically feasible but brittle. It requires precise synchronization between the local file system state and the Composer dependency graph. By managing the library strictly through composer.json and leveraging the generated autoloader, you avoid the "Class not found" errors that stem from missing vendor directories or outdated autoload maps.

Our network