engelsystem/includes/helper/email_helper.php

35 lines
944 B
PHP
Raw Normal View History

2013-12-26 13:34:48 +01:00
<?php
use Engelsystem\Mail\EngelsystemMailer;
2018-10-09 21:47:31 +02:00
use Engelsystem\Models\User\User;
2017-01-03 03:22:48 +01:00
/**
2018-10-17 01:30:10 +02:00
* @param User $recipientUser
* @param string $title
* @param string $message
* @param bool $notIfItsMe
2017-01-03 03:22:48 +01:00
* @return bool
*/
2018-10-09 21:47:31 +02:00
function engelsystem_email_to_user($recipientUser, $title, $message, $notIfItsMe = false)
2017-01-02 03:57:23 +01:00
{
2018-10-31 12:48:22 +01:00
if ($notIfItsMe && auth()->user()->id == $recipientUser->id) {
2019-04-29 23:17:58 +02:00
return true;
2017-01-02 03:57:23 +01:00
}
2017-01-02 15:43:36 +01:00
/** @var EngelsystemMailer $mailer */
$mailer = app('mailer');
$status = $mailer->sendViewTranslated(
$recipientUser,
$title,
'emails/mail',
['username' => $recipientUser->displayName, 'message' => $message]
);
2017-01-03 03:22:48 +01:00
if (!$status) {
error(sprintf(__('User %s could not be notified by email due to an error.'), $recipientUser->displayName));
engelsystem_log(sprintf('User %s could not be notified by email due to an error.', $recipientUser->name));
2017-01-02 03:57:23 +01:00
}
2017-01-03 03:22:48 +01:00
return $status;
2013-12-26 13:34:48 +01:00
}