catch mail exceptions, execute the action, inform the user about the error and create a log entry

main
msquare 6 years ago
parent 184c36baab
commit ef2d917c59

@ -13,26 +13,33 @@ use Engelsystem\Models\User\User;
function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false) function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false)
{ {
if ($notIfItsMe && auth()->user()->id == $recipientUser->id) { if ($notIfItsMe && auth()->user()->id == $recipientUser->id) {
return true; #return true;
} }
/** @var \Engelsystem\Helpers\Translator $translator */ /** @var \Engelsystem\Helpers\Translator $translator */
$translator = app()->get('translator'); $translator = app()->get('translator');
$locale = $translator->getLocale(); $locale = $translator->getLocale();
/** @var EngelsystemMailer $mailer */
$mailer = app('mailer'); try {
/** @var EngelsystemMailer $mailer */
$translator->setLocale($recipientUser->settings->language); $mailer = app('mailer');
$status = $mailer->sendView(
$recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email, $translator->setLocale($recipientUser->settings->language);
$title, $status = $mailer->sendView(
'emails/mail', $recipientUser->contact->email ? $recipientUser->contact->email : $recipientUser->email,
['username' => $recipientUser->name, 'message' => $message] $title,
); 'emails/mail',
['username' => $recipientUser->name, 'message' => $message]
);
} catch(Exception $e) {
$status = 0;
}
$translator->setLocale($locale); $translator->setLocale($locale);
if (!$status) { 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; return (bool)$status;

Loading…
Cancel
Save