<?php
/**
 * Script to download real PHPMailer files
 */

echo "<h2>Downloading Real PHPMailer Files</h2>";

// URLs for PHPMailer files
$files = [
    'https://raw.githubusercontent.com/PHPMailer/PHPMailer/master/src/PHPMailer.php' => 'includes/PHPMailer/src/PHPMailer.php',
    'https://raw.githubusercontent.com/PHPMailer/PHPMailer/master/src/SMTP.php' => 'includes/PHPMailer/src/SMTP.php',
    'https://raw.githubusercontent.com/PHPMailer/PHPMailer/master/src/Exception.php' => 'includes/PHPMailer/src/Exception.php'
];

$success = true;

foreach ($files as $url => $destination) {
    echo "<p>Downloading " . basename($destination) . "...</p>";
    
    // Download file
    $content = @file_get_contents($url);
    if ($content === false) {
        echo "<p style='color: red;'>Failed to download " . basename($destination) . "</p>";
        $success = false;
    } else {
        if (file_put_contents($destination, $content)) {
            echo "<p style='color: green;'>Successfully downloaded " . basename($destination) . "</p>";
        } else {
            echo "<p style='color: red;'>Failed to save " . basename($destination) . "</p>";
            $success = false;
        }
    }
}

if ($success) {
    echo "<p style='color: green; font-weight: bold;'>PHPMailer files downloaded successfully!</p>";
    echo "<p>Now you can test email functionality with proper SMTP support.</p>";
    echo "<p><a href='email_config_test.php'>Test Email Functionality</a></p>";
} else {
    echo "<p style='color: red; font-weight: bold;'>Failed to download PHPMailer files.</p>";
    echo "<h3>Alternative Solution:</h3>";
    echo "<p>Manually download PHPMailer from <a href='https://github.com/PHPMailer/PHPMailer'>GitHub</a>:</p>";
    echo "<ol>";
    echo "<li>Go to <a href='https://github.com/PHPMailer/PHPMailer'>https://github.com/PHPMailer/PHPMailer</a></li>";
    echo "<li>Click 'Clone or download' → 'Download ZIP'</li>";
    echo "<li>Extract the ZIP file</li>";
    echo "<li>Copy the 'src' folder contents to <code>includes/PHPMailer/src/</code></li>";
    echo "<li>Then <a href='email_config_test.php'>test email functionality</a></li>";
    echo "</ol>";
}

echo "<p><a href='index.php'>Back to Home</a></p>";
?>