<?php
/**
 * Autoloader for PHPMailer (manual installation)
 * Works with PHPMailer-master folder structure
 */

spl_autoload_register(function ($class) {
    // PHPMailer namespace
    $prefix = 'PHPMailer\\PHPMailer\\';
    
    // Try both possible paths
    $paths = [
        __DIR__ . '/phpmailer/phpmailer/src/',      // composer structure
        __DIR__ . '/PHPMailer-master/src/',          // manual download structure
    ];
    
    // Check if class uses the PHPMailer namespace
    $len = strlen($prefix);
    if (strncmp($prefix, $class, $len) !== 0) {
        return;
    }
    
    // Get the relative class name
    $relative_class = substr($class, $len);
    
    // Try each path
    foreach ($paths as $base_dir) {
        $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php';
        if (file_exists($file)) {
            require $file;
            return;
        }
    }
});