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.
This commit is contained in:
Will Rossiter 2021-06-22 12:12:42 +12:00
parent e2f4378fff
commit 18eccb65d4
No known key found for this signature in database
GPG Key ID: 7FD2A809B22259EF
1 changed files with 12 additions and 2 deletions

View File

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