fix(smtp-test): catch SmtpSendException to surface delivery errors as flash messages

This commit is contained in:
Pontoporeia
2026-04-30 13:37:42 +02:00
parent 19784090a3
commit 898a87789b
3 changed files with 19 additions and 8 deletions

View File

@@ -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)

View File

@@ -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 {
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');

View File

@@ -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"}