mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-06 11:09:18 +02:00
fix(smtp-test): catch SmtpSendException to surface delivery errors as flash messages
This commit is contained in:
@@ -32,14 +32,14 @@ if (!SmtpRelay::isConfigured($db)) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$subject = 'Test SMTP — XAMXAM';
|
||||
$subject = 'Test SMTP - XAMXAM';
|
||||
$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 — XAMXAM
|
||||
Test d'envoi SMTP - XAMXAM
|
||||
</h1>
|
||||
<p>Ceci est un e-mail de test envoyé depuis l'interface d'administration de <strong>XAMXAM</strong>.</p>
|
||||
<p>Si vous recevez ce message, la configuration du relay SMTP est correcte.</p>
|
||||
@@ -52,12 +52,18 @@ $body = <<<HTML
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
$ok = SmtpRelay::send($db, $to, $subject, $body);
|
||||
|
||||
if ($ok) {
|
||||
App::flash('success', "E-mail de test envoyé à « {$to} ».");
|
||||
} else {
|
||||
App::flash('error', "Échec de l'envoi. Vérifiez la configuration SMTP et les logs serveur.");
|
||||
try {
|
||||
$ok = SmtpRelay::send($db, $to, $subject, $body);
|
||||
if ($ok) {
|
||||
App::flash('success', "E-mail de test envoyé à « {$to} ».");
|
||||
} else {
|
||||
App::flash('error', "Échec de l'envoi. Vérifiez la configuration SMTP et les logs serveur.");
|
||||
}
|
||||
} catch (SmtpSendException $e) {
|
||||
$detail = $e->isRecipientRejected()
|
||||
? "Adresse rejetée par le serveur ({$to}) : " . $e->smtpResponse
|
||||
: "Erreur SMTP : " . $e->smtpResponse;
|
||||
App::flash('error', $detail);
|
||||
}
|
||||
|
||||
header('Location: /admin/parametres.php');
|
||||
|
||||
Reference in New Issue
Block a user