engelsystem/includes/helper/email_helper.php

41 lines
999 B
PHP
Raw Normal View History

2013-12-26 13:34:48 +01:00
<?php
use Engelsystem\Mail\EngelsystemMailer;
2017-01-03 03:22:48 +01:00
/**
* @param array $recipient_user
* @param string $title
* @param string $message
* @param bool $not_if_its_me
* @return bool
*/
2017-01-02 03:57:23 +01:00
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false)
{
global $user;
2017-01-02 15:43:36 +01:00
2017-01-02 03:57:23 +01:00
if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
return true;
}
2017-01-02 15:43:36 +01:00
/** @var \Engelsystem\Helpers\Translator $translator */
$translator = app()->get('translator');
$locale = $translator->getLocale();
/** @var EngelsystemMailer $mailer */
$mailer = app('mailer');
2017-01-02 15:43:36 +01:00
$translator->setLocale($recipient_user['Sprache']);
$status = $mailer->sendView(
$recipient_user['email'],
2017-01-03 03:22:48 +01:00
$title,
'emails/mail',
['username' => $recipient_user['Nick'], 'message' => $message]
2017-01-03 03:22:48 +01:00
);
$translator->setLocale($locale);
2017-01-03 03:22:48 +01:00
if (!$status) {
2017-01-02 03:57:23 +01:00
engelsystem_error('Unable to send email.');
}
2017-01-03 03:22:48 +01:00
return (bool)$status;
2013-12-26 13:34:48 +01:00
}