summaryrefslogtreecommitdiff
path: root/includes/email.php
blob: a85d5f67f094b8fefde84400a8035197376c13fe (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<?php

use PHPMailer\PHPMailer\PHPMailer;

require $_SERVER['DOCUMENT_ROOT'] . '/includes/PHPMailer/src/Exception.php';
require $_SERVER['DOCUMENT_ROOT'] . '/includes/PHPMailer/src/PHPMailer.php';
require $_SERVER['DOCUMENT_ROOT'] . '/includes/PHPMailer/src/SMTP.php';

$emailConfig = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.json"), true);

function sendCode($email, $code) {
    global $emailConfig;

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'in-v3.mailjet.com';
    $mail->SMTPAuth = true;
    $mail->Username = $emailConfig["username"];
    $mail->Password = $emailConfig["password"];
    $mail->SMTPSecure = "none";
    $mail->Port = 587;

    $mail->setFrom('delta@auto.minteck.org', 'Delta');
    $mail->addAddress($email);
    $mail->addReplyTo(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email")), 'Equestria.dev');

    $mail->isHTML();
    $mail->Subject = l("lang_email_code_title");

    $body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.html");
    $body = str_replace("%3", date('Y'), $body);
    $body = str_replace("%2", l("lang_email_reasons_login"), $body);
    $body = str_replace("%1", "<p>" . l("lang_email_code_message_0") . "</p><p>" . l("lang_email_code_message_1") . "</p><p>" . $code . "</p><p><b>" . l("lang_email_code_message_2") . "</b></p><p>" . l("lang_email_code_message_3") . "</p>", $body);

    $mail->CharSet = 'UTF-8';
    $mail->Body = $body;
    $mail->AltBody = strip_tags($body);

    $mail->send();
}

function sendRegistration($email, $name, $id) {
    global $emailConfig;

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'in-v3.mailjet.com';
    $mail->SMTPAuth = true;
    $mail->Username = $emailConfig["username"];
    $mail->Password = $emailConfig["password"];
    $mail->SMTPSecure = "none";
    $mail->Port = 587;

    $mail->setFrom('delta@auto.minteck.org', 'Delta');
    $mail->addAddress($email);
    $mail->addReplyTo(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email")), 'Equestria.dev');

    $mail->isHTML();
    $mail->Subject = str_replace("%1", $id, l("lang_register_email_title"));
    $mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'] . "/logo.png", "logo", "logo.png");

    $body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.html");
    $body = str_replace("%3", date('Y'), $body);
    $body = str_replace("%2", l("lang_register_email_reason"), $body);
    $body = str_replace("%1", "<p>" . str_replace("%1", strip_tags($name), l("lang_register_email_content_0")) . "</p><p>" . l("lang_register_email_content_1") . "</p><p>" . str_replace("%1", strip_tags($id), l("lang_register_email_content_2")) . "</p><p>" . l("lang_register_email_content_3") . "</p>", $body);

    $mail->CharSet = 'UTF-8';
    $mail->Body = $body;
    $mail->AltBody = strip_tags($body);

    $mail->send();
}

function sendRegistrationApproval($email, $name, $id) {
    global $emailConfig;

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'in-v3.mailjet.com';
    $mail->SMTPAuth = true;
    $mail->Username = $emailConfig["username"];
    $mail->Password = $emailConfig["password"];
    $mail->SMTPSecure = "none";
    $mail->Port = 587;

    $mail->setFrom('delta@auto.minteck.org', 'Delta');
    $mail->addAddress($email);
    $mail->addReplyTo(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email")), 'Equestria.dev');

    $mail->isHTML();
    $mail->Subject = str_replace("%1", $id, l("lang_register_approved_title"));
    $mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'] . "/logo.png", "logo", "logo.png");

    $body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.html");
    $body = str_replace("%3", date('Y'), $body);
    $body = str_replace("%2", l("lang_register_email_reason"), $body);
    $body = str_replace("%1", "<p>" . str_replace("%1", strip_tags($name), l("lang_register_approved_content_0")) . "</p><p>" . l("lang_register_approved_content_1") . "</p><p>" . l("lang_register_approved_content_2") . "</p><p>" . l("lang_register_approved_content_3") . "</p>", $body);

    $mail->CharSet = 'UTF-8';
    $mail->Body = $body;
    $mail->AltBody = strip_tags($body);

    $mail->send();
}

function sendRegistrationRejection($email, $name, $id, $reason) {
    global $emailConfig;

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'in-v3.mailjet.com';
    $mail->SMTPAuth = true;
    $mail->Username = $emailConfig["username"];
    $mail->Password = $emailConfig["password"];
    $mail->SMTPSecure = "none";
    $mail->Port = 587;

    $mail->setFrom('delta@auto.minteck.org', 'Delta');
    $mail->addAddress($email);
    $mail->addReplyTo(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email")), 'Equestria.dev');

    $mail->isHTML();
    $mail->Subject = str_replace("%1", $id, l("lang_register_rejected_title"));
    $mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'] . "/logo.png", "logo", "logo.png");

    $body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.html");
    $body = str_replace("%3", date('Y'), $body);
    $body = str_replace("%2", l("lang_register_email_reason"), $body);
    $body = str_replace("%1", "<p>" . str_replace("%1", strip_tags($name), l("lang_register_rejected_content_0")) . "</p><p>" . str_replace("%1", (isset($reason) && trim($reason) !== "" ? l("lang_register_rejected_content_5") . "<blockquote>" . strip_tags($reason) . "</blockquote>" : l("lang_register_rejected_content_4")), l("lang_register_rejected_content_1")) . "</p><p>" . l("lang_register_rejected_content_2") . "</p><p>" . l("lang_register_rejected_content_3") . "</p>", $body);

    $mail->CharSet = 'UTF-8';
    $mail->Body = $body;
    $mail->AltBody = strip_tags($body);

    $mail->send();
}

function sendPlanUpdate($email, $plan) {
    global $emailConfig;

    $price = (float)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/plusprice"));

    switch ($plan) {
        case 0:
        default:
            $monthFee = 0;
            $name = "Delta Free";
            break;

        case 1:
            $monthFee = $price;
            $name = "Delta Plus";
            break;

        case 2:
            $monthFee = $price + 2;
            $name = "Delta Ultra";
            break;
    }

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'in-v3.mailjet.com';
    $mail->SMTPAuth = true;
    $mail->Username = $emailConfig["username"];
    $mail->Password = $emailConfig["password"];
    $mail->SMTPSecure = "none";
    $mail->Port = 587;

    $mail->setFrom('delta@auto.minteck.org', 'Delta');
    $mail->addAddress($email);
    $mail->addReplyTo(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email")), 'Equestria.dev');

    $mail->isHTML();
    $mail->Subject = l("lang_email_plan_title");
    $mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'] . "/logo.png", "logo", "logo.png");

    $body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.html");
    $body = str_replace("%3", date('Y'), $body);
    $body = str_replace("%2", l("lang_email_reasons_update"), $body);
    $body = str_replace("%1", "<p>" . l("lang_email_plan_message_0") . "</p><p>" . str_replace("%2", $monthFee, str_replace("%1", "<b>" . $name . "</b>", l("lang_email_plan_message_1"))) . "</p><p>" . l("lang_email_plan_message_2") . "</p><p>" . l("lang_email_plan_message_3") . "</p>", $body);

    $mail->CharSet = 'UTF-8';
    $mail->Body = $body;
    $mail->AltBody = strip_tags($body);

    $mail->send();
}

function sendAlerts($email, $alerts) {
    global $emailConfig;

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'in-v3.mailjet.com';
    $mail->SMTPAuth = true;
    $mail->Username = $emailConfig["username"];
    $mail->Password = $emailConfig["password"];
    $mail->SMTPSecure = "none";
    $mail->Port = 587;

    $mail->setFrom('delta@auto.minteck.org', 'Delta');
    $mail->addAddress($email);
    $mail->addReplyTo(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email")), 'Equestria.dev');

    $mail->isHTML();

    if (count($alerts) > 1) {
        $mail->Subject = str_replace("%1", count($alerts), l("lang_email_alerts_title_0"));
    } else {
        $mail->Subject = l("lang_email_alerts_title_1");
    }
    $mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'] . "/logo.png", "logo", "logo.png");

    $body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.html");
    $body = str_replace("%3", date('Y'), $body);
    $body = str_replace("%2", l("lang_email_reasons_alert"), $body);
    $text = "<p>" . l("lang_email_alerts_message_0") . "</p><p>" . l("lang_email_alerts_message_1") . "</p>";

    foreach ($alerts as $alert) {
        $text .= "<p><b>" . $alert["title"] . "</b><br>" . $alert["message"] . "</p>";
    }

    $text .= "<p>" . l("lang_email_alerts_message_2") . "</p>";
    $body = str_replace("%1", $text, $body);

    $mail->CharSet = 'UTF-8';
    $mail->Body = $body;
    $mail->AltBody = strip_tags($body);

    $mail->send();
}

function sendLogin($email) {
    global $emailConfig;

    $mail = new PHPMailer(true);
    $mail->isSMTP();
    $mail->Host = 'in-v3.mailjet.com';
    $mail->SMTPAuth = true;
    $mail->Username = $emailConfig["username"];
    $mail->Password = $emailConfig["password"];
    $mail->SMTPSecure = "none";
    $mail->Port = 587;

    $mail->setFrom('delta@auto.minteck.org', 'Delta');
    $mail->addAddress($email);
    $mail->addReplyTo(trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email")), 'Equestria.dev');

    $mail->isHTML();
    $mail->Subject = l("lang_email_login_title");
    $mail->addEmbeddedImage($_SERVER['DOCUMENT_ROOT'] . "/logo.png", "logo", "logo.png");

    $location = json_decode(file_get_contents("https://api.iplocation.net/?ip=" . $_SERVER['HTTP_X_FORWARDED_FOR']), true);

    $body = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/email.html");
    $body = str_replace("%3", date('Y'), $body);
    $body = str_replace("%2", l("lang_email_reasons_login2"), $body);
    $body = str_replace("%1", "<p>" . l("lang_email_login_message_0") . "</p><p>" . l("lang_email_login_message_1") . "</p><p>" . $location["country_name"] . " (" . $_SERVER['HTTP_X_FORWARDED_FOR'] . ", " . $location["isp"] . ")<br>" . $_SERVER["HTTP_USER_AGENT"] . "</p><p>" . l("lang_email_login_message_2") . "</p><p>" . l("lang_email_login_message_3") . "</p>", $body);

    $mail->CharSet = 'UTF-8';
    $mail->Body = $body;
    $mail->AltBody = strip_tags($body);

    $mail->send();
}