summaryrefslogtreecommitdiff
path: root/includes/helper/email_helper.php
blob: a063155024235061b3b78001b6a6fe4a95b02cd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php

/**
 * @param array  $recipient_user
 * @param string $title
 * @param string $message
 * @param bool   $not_if_its_me
 * @return bool
 */
function engelsystem_email_to_user($recipient_user, $title, $message, $not_if_its_me = false)
{
    global $user;

    if ($not_if_its_me && $user['UID'] == $recipient_user['UID']) {
        return true;
    }

    /** @var \Engelsystem\Helpers\Translator $translator */
    $translator = app()->get('translator');
    $locale = $translator->getLocale();

    $translator->setLocale($recipient_user['Sprache']);
    $message = sprintf(__('Hi %s,'), $recipient_user['Nick']) . "\n\n"
        . __('here is a message for you from the engelsystem:') . "\n\n"
        . $message . "\n\n"
        . __('This email is autogenerated and has not been signed. You got this email because you are registered in the engelsystem.');
    $translator->setLocale($locale);

    return engelsystem_email($recipient_user['email'], $title, $message);
}

/**
 * @param string $address
 * @param string $title
 * @param string $message
 * @return bool
 */
function engelsystem_email($address, $title, $message)
{
    $result = mail(
        $address,
        $title,
        $message,
        sprintf(
            "Content-Type: text/plain; charset=UTF-8\r\nFrom: Engelsystem <%s>",
            config('no_reply_email')
        )
    );

    if ($result === false) {
        engelsystem_error('Unable to send email.');
    }

    return true;
}