From 18eccb65d426ec4ea873b1231789c6e8cf58ed94 Mon Sep 17 00:00:00 2001 From: Will Rossiter Date: Tue, 22 Jun 2021 12:12:42 +1200 Subject: [PATCH] FIX Log any email exceptions gracefully If an email send() generates any errors such as invalid template or API exceptions then capture the error in the logs rather than displaying the error to the user. --- code/Control/UserDefinedFormController.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/code/Control/UserDefinedFormController.php b/code/Control/UserDefinedFormController.php index 460fb12..47ac253 100644 --- a/code/Control/UserDefinedFormController.php +++ b/code/Control/UserDefinedFormController.php @@ -2,6 +2,7 @@ namespace SilverStripe\UserForms\Control; +use Exception; use PageController; use Psr\Log\LoggerInterface; use SilverStripe\AssetAdmin\Controller\AssetAdmin; @@ -429,9 +430,18 @@ JS } $email->setBody($body); - $email->sendPlain(); + + try { + $email->sendPlain(); + } catch (Exception $e) { + Injector::inst()->get(LoggerInterface::class)->error($e); + } } else { - $email->send(); + try { + $email->send(); + } catch (Exception $e) { + Injector::inst()->get(LoggerInterface::class)->error($e); + } } } }