forked from htmlacademy-php1/2074903-doingsdone-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotify.php
More file actions
47 lines (39 loc) · 1.52 KB
/
notify.php
File metadata and controls
47 lines (39 loc) · 1.52 KB
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
<?php
require_once 'init.php';
require_once 'model.php';
require_once 'helpers.php';
require_once 'myfunction.php';
require_once 'config/smtp.php';
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require_once 'vendor/autoload.php';
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = SMTP::DEBUG_SERVER;
$mail->Host = $smtp['host'];
$mail->Port = $smtp['port'];
$mail->SMTPSecure = $smtp['secure'];
$mail->SMTPAuth = true;
$mail->Username = $smtp['username'];
$mail->Password = $smtp['password'];
$mail->setFrom('keks@phpdemo.ru', 'doingsdone');
$users_notify = get_users_notify($con);
$date = date('Y-m-d', strtotime("now"));
foreach ($users_notify as $user) {
$user_id = $user['id'];
$tasks_notify = get_tasks_notify($con, $user_id, $date);
if (!empty($tasks_notify)) {
$tasks = array_column($tasks_notify, 'name');
$mail->addAddress($user['email'], $user['name']);
$mail->Subject = 'Уведомление от сервиса «Дела в порядке»';
$mail->Body = 'Уважаемый, ' . $user['name']
. '. У вас запланирована задача ' . implode(", ", $tasks) . ' на ' . $date;
$mail->AltBody = 'Уважаемый, ' . $user['name']
. '. У вас запланирована задача ' . implode(", ", $tasks) . ' на ' . $date;
if (!$mail->send()) {
echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
echo 'Message sent!';
}
}
}