| SMTP Host: | |
| Port: | |
| Username: | |
| Encryption: |
Tips:
- Use an App Password for Gmail
- Hostinger: Port 465 (SSL) or 587 (TLS)
- Send a test email after changing settings
- PHPMailer library must be installed
65535) $errors[] = 'A valid port number (1-65535) is required.';
if (empty($username)) $errors[] = 'Username is required.';
if (empty($password)) $errors[] = 'Password is required.';
if (!in_array($encryption, ['ssl', 'tls'])) $errors[] = 'Select a valid encryption type (SSL or TLS).';
if (!filter_var($username, FILTER_VALIDATE_EMAIL)) $errors[] = 'Enter a valid email address.';
if (!empty($errors)) {
throw new Exception(implode('
', $errors));
}
// Check if record exists
$stmt = $db->prepare("SELECT COUNT(*) FROM smtp_settings WHERE id = 1");
$stmt->execute();
$exists = $stmt->fetchColumn();
if ($exists) {
// Update existing record
$stmt = $db->prepare("
UPDATE smtp_settings
SET host = ?, port = ?, username = ?, password = ?, encryption = ?
WHERE id = 1
");
$stmt->execute([$host, $port, $username, $password, $encryption]);
} else {
// Insert new record
$stmt = $db->prepare("
INSERT INTO smtp_settings (id, host, port, username, password, encryption)
VALUES (1, ?, ?, ?, ?, ?)
");
$stmt->execute([$host, $port, $username, $password, $encryption]);
}
$message = 'SMTP settings successfully updated!';
} catch (Exception $e) {
$error = 'Error updating SMTP settings: ' . $e->getMessage();
logError($error);
}
} elseif (isset($_POST['action']) && $_POST['action'] === 'test_email') {
try {
$test_email = trim(sanitizeInput($_POST['test_email']));
if (!filter_var($test_email, FILTER_VALIDATE_EMAIL)) {
throw new Exception('Enter a valid email address.');
}
$subject = "SMTP Test Email - " . ORGANIZATION_NAME;
$body = "
This is a test email sent to verify that your SMTP settings are working correctly.
Sent Time: " . date('d-m-Y H:i:s') . "
Organization: " . ORGANIZATION_NAME . "
If you received this email, your SMTP settings have been successfully configured.
| SMTP Host: | |
| Port: | |
| Username: | |
| Encryption: |