mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
feat(admin): add SMTP test email button on parametres page
This commit is contained in:
64
app/public/admin/actions/smtp-test.php
Normal file
64
app/public/admin/actions/smtp-test.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require_once __DIR__ . "/../../../bootstrap.php";
|
||||
require_once __DIR__ . '/../../../src/AdminAuth.php';
|
||||
AdminAuth::requireLogin();
|
||||
|
||||
require_once APP_ROOT . '/src/Database.php';
|
||||
require_once APP_ROOT . '/src/SmtpRelay.php';
|
||||
require_once APP_ROOT . '/src/App.php';
|
||||
|
||||
// CSRF
|
||||
if (
|
||||
!isset($_POST['csrf_token'], $_SESSION['csrf_token']) ||
|
||||
!hash_equals($_SESSION['csrf_token'], $_POST['csrf_token'])
|
||||
) {
|
||||
App::flash('error', 'Erreur de sécurité : token invalide.');
|
||||
header('Location: /admin/parametres.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$to = trim($_POST['test_email'] ?? '');
|
||||
if ($to === '' || !filter_var($to, FILTER_VALIDATE_EMAIL)) {
|
||||
App::flash('error', 'Adresse e-mail de test invalide.');
|
||||
header('Location: /admin/parametres.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$db = new Database();
|
||||
|
||||
if (!SmtpRelay::isConfigured($db)) {
|
||||
App::flash('error', 'Le relay SMTP n\'est pas configuré.');
|
||||
header('Location: /admin/parametres.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
$subject = 'Test SMTP — Post-ERG';
|
||||
$sentDate = date('d/m/Y à H:i:s');
|
||||
$toSafe = htmlspecialchars($to);
|
||||
$body = <<<HTML
|
||||
<html>
|
||||
<body style="font-family: sans-serif; color: #222; max-width: 600px; margin: 0 auto; padding: 24px;">
|
||||
<h1 style="font-size: 1.4rem; border-bottom: 2px solid #c00; padding-bottom: 8px;">
|
||||
Test d'envoi SMTP — Post-ERG
|
||||
</h1>
|
||||
<p>Ceci est un e-mail de test envoyé depuis l'interface d'administration de <strong>Post-ERG</strong>.</p>
|
||||
<p>Si vous recevez ce message, la configuration du relay SMTP est correcte.</p>
|
||||
<hr style="border:none; border-top:1px solid #ddd; margin: 24px 0;">
|
||||
<p style="font-size: 0.85rem; color: #666;">
|
||||
Envoyé le : $sentDate<br>
|
||||
Destinataire : $toSafe
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
$ok = SmtpRelay::send($db, $to, $subject, $body);
|
||||
|
||||
if ($ok) {
|
||||
App::flash('success', "E-mail de test envoyé à \u00ab\u00a0{$to}\u00a0\u00bb.");
|
||||
} else {
|
||||
App::flash('error', "Échec de l'envoi. Vérifiez la configuration SMTP et les logs serveur.");
|
||||
}
|
||||
|
||||
header('Location: /admin/parametres.php');
|
||||
exit;
|
||||
@@ -1483,6 +1483,47 @@ label:has(+ div > input:required)::after {
|
||||
|
||||
|
||||
/* ── SMTP section ─────────────────────────────────────────────────────── */
|
||||
.param-smtp-test {
|
||||
margin-top: var(--space-m);
|
||||
}
|
||||
.param-smtp-test-form {
|
||||
margin-top: var(--space-s);
|
||||
}
|
||||
.param-smtp-test-row {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: var(--space-s);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.param-smtp-test-row > div {
|
||||
flex: 1 1 260px;
|
||||
}
|
||||
.param-smtp-test-row label {
|
||||
display: block;
|
||||
font-size: var(--step--1);
|
||||
font-weight: 600;
|
||||
margin-bottom: var(--space-2xs);
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
.param-smtp-test-row input[type="email"] {
|
||||
width: 100%;
|
||||
padding: var(--space-xs) var(--space-s);
|
||||
border: 1px solid var(--border-primary);
|
||||
border-radius: 4px;
|
||||
background: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
font-size: var(--step--1);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.param-smtp-test-row input[type="email"]:focus {
|
||||
outline: 2px solid var(--accent-primary);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
.param-smtp-test-row > button {
|
||||
white-space: nowrap;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.param-smtp-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -186,6 +186,27 @@
|
||||
|
||||
<button type="submit">Enregistrer</button>
|
||||
</form>
|
||||
|
||||
<!-- Test d'envoi -->
|
||||
<fieldset class="param-fieldset-inline param-smtp-test">
|
||||
<legend>Tester l'envoi d'un e-mail</legend>
|
||||
<p>Envoie un e-mail de test via le relay SMTP configuré ci-dessus.</p>
|
||||
<?php if (!$smtpConfigured): ?>
|
||||
<p class="param-note">⚠ Configurez le relay SMTP avant de pouvoir tester l'envoi.</p>
|
||||
<?php else: ?>
|
||||
<form method="post" action="actions/smtp-test.php" class="param-form param-smtp-test-form">
|
||||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($_SESSION['csrf_token']) ?>">
|
||||
<div class="param-smtp-test-row">
|
||||
<div>
|
||||
<label for="smtp_test_email">Adresse de destination</label>
|
||||
<input type="email" id="smtp_test_email" name="test_email"
|
||||
placeholder="test@example.com" required>
|
||||
</div>
|
||||
<button type="submit">Envoyer le test</button>
|
||||
</div>
|
||||
</form>
|
||||
<?php endif; ?>
|
||||
</fieldset>
|
||||
</section>
|
||||
|
||||
<!-- ══════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user