Sindbad~EG File Manager

Current Path : /home/copmadinaarea/.trash/
Upload File :
Current File : /home/copmadinaarea/.trash/fix_smtp_settings.php

<?php
/**
 * Fix SMTP Settings - Remove Extra Spaces
 * Run this once to clean up SMTP settings in the database
 */

require_once 'config/config.php';

// Check if user is logged in and is superuser
if (!isLoggedIn() || !isSuperuser()) {
    die('Access denied. This script requires superuser access.');
}

try {
    $db = Database::getInstance()->getConnection();
    
    // Get current settings
    $stmt = $db->query("SELECT * FROM email_settings ORDER BY id DESC LIMIT 1");
    $settings = $stmt->fetch();
    
    if (!$settings) {
        die('No email settings found.');
    }
    
    echo "<h2>Fixing SMTP Settings</h2>";
    echo "<p>Cleaning up whitespace from SMTP configuration...</p>";
    
    // Show before values
    echo "<h3>Before:</h3>";
    echo "<pre>";
    echo "SMTP Host: '" . $settings['smtp_host'] . "' (length: " . strlen($settings['smtp_host']) . ")\n";
    echo "SMTP Port: '" . $settings['smtp_port'] . "' (length: " . strlen($settings['smtp_port']) . ")\n";
    echo "SMTP Username: '" . $settings['smtp_username'] . "' (length: " . strlen($settings['smtp_username']) . ")\n";
    echo "From Email: '" . $settings['from_email'] . "' (length: " . strlen($settings['from_email']) . ")\n";
    echo "From Name: '" . $settings['from_name'] . "' (length: " . strlen($settings['from_name']) . ")\n";
    echo "</pre>";
    
    // Trim all fields
    $stmt = $db->prepare("
        UPDATE email_settings 
        SET smtp_host = TRIM(smtp_host),
            smtp_port = TRIM(smtp_port),
            smtp_username = TRIM(smtp_username),
            smtp_password = TRIM(smtp_password),
            from_email = TRIM(from_email),
            from_name = TRIM(from_name)
        WHERE id = :id
    ");
    
    $stmt->execute(['id' => $settings['id']]);
    
    // Get updated settings
    $stmt = $db->query("SELECT * FROM email_settings ORDER BY id DESC LIMIT 1");
    $cleanSettings = $stmt->fetch();
    
    // Show after values
    echo "<h3>After:</h3>";
    echo "<pre>";
    echo "SMTP Host: '" . $cleanSettings['smtp_host'] . "' (length: " . strlen($cleanSettings['smtp_host']) . ")\n";
    echo "SMTP Port: '" . $cleanSettings['smtp_port'] . "' (length: " . strlen($cleanSettings['smtp_port']) . ")\n";
    echo "SMTP Username: '" . $cleanSettings['smtp_username'] . "' (length: " . strlen($cleanSettings['smtp_username']) . ")\n";
    echo "From Email: '" . $cleanSettings['from_email'] . "' (length: " . strlen($cleanSettings['from_email']) . ")\n";
    echo "From Name: '" . $cleanSettings['from_name'] . "' (length: " . strlen($cleanSettings['from_name']) . ")\n";
    echo "</pre>";
    
    echo "<div style='background: #d1fae5; border: 2px solid #10b981; padding: 15px; border-radius: 8px; margin: 20px 0;'>";
    echo "<h3 style='color: #047857; margin: 0 0 10px 0;'>✅ Success!</h3>";
    echo "<p style='margin: 0;'>SMTP settings have been cleaned. All extra spaces removed.</p>";
    echo "</div>";
    
    echo "<p><a href='modules/email/index.php' style='display: inline-block; background: linear-gradient(135deg, #1E40AF 0%, #9333EA 100%); color: white; padding: 12px 24px; border-radius: 8px; text-decoration: none; font-weight: bold;'>← Back to Email Management</a></p>";
    
    echo "<p style='color: #666; font-size: 14px; margin-top: 30px;'><strong>Note:</strong> You can delete this file (fix_smtp_settings.php) after running it.</p>";
    
} catch (Exception $e) {
    echo "<div style='background: #fee2e2; border: 2px solid #ef4444; padding: 15px; border-radius: 8px;'>";
    echo "<h3 style='color: #dc2626; margin: 0 0 10px 0;'>❌ Error</h3>";
    echo "<p style='margin: 0;'>" . htmlspecialchars($e->getMessage()) . "</p>";
    echo "</div>";
}
?>

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists