summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2019-04-28 14:54:32 +0200
committermsquare <msquare@notrademark.de>2019-04-28 14:54:32 +0200
commitef2d917c59213e9f6e277004c9cb4c22ae66b08e (patch)
tree64fe2e19a1bd38ee60517fc310b4de17f9dfba9d
parent184c36baab3116c002db2b054afa9952c2ba3634 (diff)
catch mail exceptions, execute the action, inform the user about the error and create a log entry
-rw-r--r--includes/helper/email_helper.php29
1 files changed, 18 insertions, 11 deletions
diff --git a/includes/helper/email_helper.php b/includes/helper/email_helper.php
index b5a4060d..802debaa 100644
--- a/includes/helper/email_helper.php
+++ b/includes/helper/email_helper.php
@@ -13,26 +13,33 @@ use Engelsystem\Models\User\User;
function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false)
{
if ($notIfItsMe && auth()->user()->id == $recipientUser->id) {
- return true;
+ #return true;
}
/** @var \Engelsystem\Helpers\Translator $translator */
$translator = app()->get('translator');
$locale = $translator->getLocale();
- /** @var EngelsystemMailer $mailer */
- $mailer = app('mailer');
+
+ try {
+ /** @var EngelsystemMailer $mailer */
+ $mailer = app('mailer');
+
+ $translator->setLocale($recipientUser->settings->language);
+ $status = $mailer->sendView(
+ $recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email,
+ $title,
+ 'emails/mail',
+ ['username' => $recipientUser->name, 'message' => $message]
+ );
+ } catch(Exception $e) {
+ $status = 0;
+ }
- $translator->setLocale($recipientUser->settings->language);
- $status = $mailer->sendView(
- $recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email,
- $title,
- 'emails/mail',
- ['username' => $recipientUser->name, 'message' => $message]
- );
$translator->setLocale($locale);
if (!$status) {
- engelsystem_error('Unable to send email.');
+ error(sprintf(__('User %s could not be notified by email due to an error.'), User_Nick_render($recipientUser)));
+ engelsystem_log(sprintf('User %s could not be notified by email due to an error.', $recipientUser->name));
}
return (bool)$status;