From e123e4a5c79f899b489e1ea8e3af4b7ec3b14548 Mon Sep 17 00:00:00 2001 From: ocjorge Date: Mon, 6 Jul 2026 23:21:57 -0600 Subject: [PATCH 1/3] fix: prevent fatal error when mail is not configured in Career Portal Without this change, CareerPortal::sendEmail() throws an uncaught PHPMailer exception when no mail server is configured, causing a fatal 500 error that prevents candidates from completing their application through the Career Portal. Wrapping the mail send in try/catch allows the application flow to continue normally when mail is unavailable, while still logging the error class and code for debugging without exposing sensitive SMTP configuration details in logs. Tested on PHP 8.4.21 + Debian 12 without a configured mail server. --- lib/CareerPortal.php | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/CareerPortal.php b/lib/CareerPortal.php index f420d0d85..9bd3afa77 100755 --- a/lib/CareerPortal.php +++ b/lib/CareerPortal.php @@ -458,13 +458,22 @@ public function sendEmail($userID, $destination, $subject, $body) /* Send e-mail notification. */ //FIXME: Make subject configurable. - $mailer = new Mailer($this->_siteID, $userID); - $mailerStatus = $mailer->sendToOne( - array($destination, ''), - $subject, - $body, - true - ); + try { + $mailer = new Mailer($this->_siteID, $userID); + $mailerStatus = $mailer->sendToOne( + array($destination, ''), + $subject, + $body, + true + ); + } catch (Exception $e) { + // Mail not configured or unavailable - log and continue + error_log( + 'OpenCATS CareerPortal mail error (site=' . $this->_siteID . '): ' + . get_class($e) . ' [' . $e->getCode() . ']' + ); + $mailerStatus = false; + } } } From 9de0586b0e31e630ed6f9fa7f1a3b82c9a8cd1a6 Mon Sep 17 00:00:00 2001 From: ocjorge Date: Mon, 6 Jul 2026 23:43:53 -0600 Subject: [PATCH 2/3] fix: catch PHPMailer exception specifically and use Allman braces - Catch \PHPMailer\PHPMailer\Exception instead of base Exception to avoid swallowing unrelated application errors - Use Allman brace style to match existing code conventions --- lib/CareerPortal.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/CareerPortal.php b/lib/CareerPortal.php index 9bd3afa77..041683171 100755 --- a/lib/CareerPortal.php +++ b/lib/CareerPortal.php @@ -458,7 +458,8 @@ public function sendEmail($userID, $destination, $subject, $body) /* Send e-mail notification. */ //FIXME: Make subject configurable. - try { + try + { $mailer = new Mailer($this->_siteID, $userID); $mailerStatus = $mailer->sendToOne( array($destination, ''), @@ -466,7 +467,9 @@ public function sendEmail($userID, $destination, $subject, $body) $body, true ); - } catch (Exception $e) { + } + catch (\PHPMailer\PHPMailer\Exception $e) + { // Mail not configured or unavailable - log and continue error_log( 'OpenCATS CareerPortal mail error (site=' . $this->_siteID . '): ' From e668f2f5132e07591fcdfcd904844ef6ff64173c Mon Sep 17 00:00:00 2001 From: ocjorge Date: Wed, 8 Jul 2026 19:27:18 -0600 Subject: [PATCH 3/3] fix: remove unused mailerStatus variable flagged by Codacy --- lib/CareerPortal.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/CareerPortal.php b/lib/CareerPortal.php index 041683171..fdf3b6ec6 100755 --- a/lib/CareerPortal.php +++ b/lib/CareerPortal.php @@ -461,7 +461,7 @@ public function sendEmail($userID, $destination, $subject, $body) try { $mailer = new Mailer($this->_siteID, $userID); - $mailerStatus = $mailer->sendToOne( + $mailer->sendToOne( array($destination, ''), $subject, $body, @@ -475,7 +475,6 @@ public function sendEmail($userID, $destination, $subject, $body) 'OpenCATS CareerPortal mail error (site=' . $this->_siteID . '): ' . get_class($e) . ' [' . $e->getCode() . ']' ); - $mailerStatus = false; } } }