<?php
/**
 * Script to create minimal PHPMailer files for testing
 */

echo "<h2>Creating Minimal PHPMailer Files</h2>";

// Create Exception.php
$exception_content = '<?php
namespace PHPMailer\PHPMailer;
class Exception extends \Exception
{
    public function errorMessage()
    {
        return \'<strong>\' . htmlspecialchars($this->getMessage()) . "</strong><br />\\n";
    }
}';

// Create SMTP.php
$smtp_content = '<?php
namespace PHPMailer\PHPMailer;
class SMTP
{
    const VERSION = \'6.5.0\';
    const CRLF = "\r\n";
    const DEBUG_OFF = 0;
    const DEBUG_CLIENT = 1;
    const DEBUG_SERVER = 2;
    const DEBUG_CONNECTION = 3;
    const DEBUG_LOWLEVEL = 4;
    
    // This is a minimal implementation for testing
    // For production, download the full file from GitHub
}';

// Create PHPMailer.php
$phpmailer_content = '<?php
namespace PHPMailer\PHPMailer;
class PHPMailer
{
    public $Mailer = \'mail\';
    public $Host = \'localhost\';
    public $Port = 25;
    public $SMTPSecure = \'\';
    public $SMTPAuth = false;
    public $Username = \'\';
    public $Password = \'\';
    public $SMTPAutoTLS = true;
    public $SMTPSecure = \'tls\';
    public $Port = 587;
    
    public function __construct($exceptions = null)
    {
        // Minimal constructor for testing
    }
    
    public function isSMTP()
    {
        $this->Mailer = \'smtp\';
    }
    
    public function isHTML($isHtml = true)
    {
        // Minimal implementation
    }
    
    public function setFrom($address, $name = \'\', $auto = true)
    {
        // Minimal implementation
        $this->From = $address;
        $this->FromName = $name;
    }
    
    public function addAddress($address, $name = \'\')
    {
        // Minimal implementation
        $this->to[] = [$address, $name];
    }
    
    public function send()
    {
        // This would normally send the email
        // For testing purposes, we\'ll return true
        error_log("PHPMailer send() called with: " . print_r($this, true));
        return true;
    }
}';

// Create files
$files = [
    'includes/PHPMailer/src/Exception.php' => $exception_content,
    'includes/PHPMailer/src/SMTP.php' => $smtp_content,
    'includes/PHPMailer/src/PHPMailer.php' => $phpmailer_content
];

$success = true;

foreach ($files as $path => $content) {
    echo "<p>Creating " . $path . "...</p>";
    
    // Create directory if it doesn't exist
    $dir = dirname($path);
    if (!file_exists($dir)) {
        mkdir($dir, 0755, true);
    }
    
    if (file_put_contents($path, $content)) {
        echo "<p style='color: green;'>Successfully created " . $path . "</p>";
    } else {
        echo "<p style='color: red;'>Failed to create " . $path . "</p>";
        $success = false;
    }
}

if ($success) {
    echo "<p style='color: green; font-weight: bold;'>Minimal PHPMailer files created successfully!</p>";
    echo "<p>Now you can test email functionality with improved SMTP support.</p>";
    echo "<p><a href='test_email.php'>Test Email Functionality</a></p>";
} else {
    echo "<p style='color: red; font-weight: bold;'>Failed to create PHPMailer files.</p>";
}

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