Handle SMTP 550 recipient-rejected errors with structured SmtpSendException

- Add SmtpSendException with smtpCode/smtpResponse/isRecipientRejected()
- smtpSend() $expect closure throws SmtpSendException (with code) instead of RuntimeException
- SmtpRelay::send() re-throws SmtpSendException so callers can inspect it
- request-access.php (new): catch 550 → roll back token+approval, return HTTP 422 with FR user message
- request-access.php (resend): catch 550 → HTTP 422 instead of silently claiming success
- StudentEmail::sendConfirmation(): catch SmtpSendException → log+false (submission not aborted)
- admin/actions/access-request.php: catch SmtpSendException post-approval → flash warning (recipient-rejected vs transient)
This commit is contained in:
Pontoporeia
2026-04-30 12:40:14 +02:00
parent 8d115dc965
commit 89b7ab476e
5 changed files with 103 additions and 6 deletions

View File

@@ -99,7 +99,13 @@ class StudentEmail {
$subject = 'Merci — ton TFE a bien été enregistré';
$htmlBody = self::buildHtml($thesis);
$result = SmtpRelay::send($db, $to, $subject, $htmlBody);
try {
$result = SmtpRelay::send($db, $to, $subject, $htmlBody);
} catch (SmtpSendException $e) {
// Confirmation email failure must not abort the successful submission.
error_log("[StudentEmail] SMTP error sending to {$to} for thesis #{$thesisId}: " . $e->getMessage());
return false;
}
if ($result) {
error_log("[StudentEmail] Confirmation sent to {$to} for thesis #{$thesisId}");