From 898a87789b0f6acbcabb748888939ea9a19aa25b Mon Sep 17 00:00:00 2001 From: Pontoporeia Date: Thu, 30 Apr 2026 13:37:42 +0200 Subject: [PATCH] fix(smtp-test): catch SmtpSendException to surface delivery errors as flash messages --- TODO.md | 3 +++ app/public/admin/actions/smtp-test.php | 22 ++++++++++++++-------- app/storage/logs/form-submissions.log | 2 ++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/TODO.md b/TODO.md index bb61fbc..1ab7af4 100644 --- a/TODO.md +++ b/TODO.md @@ -17,6 +17,9 @@ - [x] **add.php / edit.php / partage/index.php** — use `sortable.min.js` + `file-upload-queue.js` instead of `file-preview.js` - [x] **docs/file-uploads.md** — reference document covering accepted types, size limits, storage layout, ordering, labels, security, and source file index +## Bug fixes +- [x] **smtp-test.php** — wrap `SmtpRelay::send()` in `try/catch SmtpSendException` so SMTP delivery failures (e.g. 550 recipient rejected) surface as a proper flash error instead of an uncaught exception/silent crash + ## Previously completed - [x] Multi-file upload for thesis files (basic) - [x] File access restriction system (email approval workflow) diff --git a/app/public/admin/actions/smtp-test.php b/app/public/admin/actions/smtp-test.php index 9aa807f..078a924 100644 --- a/app/public/admin/actions/smtp-test.php +++ b/app/public/admin/actions/smtp-test.php @@ -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 = <<

- Test d'envoi SMTP — XAMXAM + Test d'envoi SMTP - XAMXAM

Ceci est un e-mail de test envoyé depuis l'interface d'administration de XAMXAM.

Si vous recevez ce message, la configuration du relay SMTP est correcte.

@@ -52,12 +52,18 @@ $body = << 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'); diff --git a/app/storage/logs/form-submissions.log b/app/storage/logs/form-submissions.log index 72786ae..f42cb63 100644 --- a/app/storage/logs/form-submissions.log +++ b/app/storage/logs/form-submissions.log @@ -2,3 +2,5 @@ {"source":"partage","action":"submit","status":"success","thesis_id":16,"identifier":"2025-013","author":"Emma Renard","share_slug":"20260429-DZESJT6X","timestamp":"2026-04-30T09:35:49+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0"} {"source":"partage","action":"submit","status":"success","thesis_id":17,"identifier":"2025-014","author":"Théo Marchand","share_slug":"20260429-DZESJT6X","timestamp":"2026-04-30T09:48:20+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0"} {"source":"partage","action":"submit","status":"success","thesis_id":18,"identifier":"2025-015","author":"Théo Marchand","share_slug":"20260429-DZESJT6X","timestamp":"2026-04-30T10:13:43+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0"} +{"source":"partage","action":"submit","status":"success","thesis_id":19,"identifier":"2025-016","author":"Lila Dubois, Karim Nassar","share_slug":"20260429-DZESJT6X","timestamp":"2026-04-30T11:27:07+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0"} +{"source":"partage","action":"submit","status":"success","thesis_id":20,"identifier":"2025-017","author":"Théo Marchand","share_slug":"20260429-DZESJT6X","timestamp":"2026-04-30T11:37:11+00:00","ip":"127.0.0.1","user_agent":"Mozilla/5.0 (X11; Linux x86_64; rv:150.0) Gecko/20100101 Firefox/150.0"}