forked from WWBN/AVideo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emailAllUsers.json.php
73 lines (69 loc) · 2.02 KB
/
emailAllUsers.json.php
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
<?php
require_once __DIR__ . DIRECTORY_SEPARATOR . 'autoload.php';
global $global, $config;
if (!isset($global['systemRootPath'])) {
require_once '../videos/configuration.php';
}
require_once $global['systemRootPath'] . 'objects/user.php';
if (!User::isAdmin()) {
header("Location: {$global['webSiteRootURL']}?error=" . __("You can not do this"));
exit;
}
setRowCount(10000);
header('Content-Type: application/json');
if (empty($_POST['email'])) {
if (!empty($_REQUEST['users_groups_id'])) {
$users = User::getAllUsersFromUsergroup(
$_REQUEST['users_groups_id'],
false,
['name', 'email', 'user', 'channelName', 'about'],
'a'
);
} else {
$users = User::getAllUsers(
false,
['name', 'email', 'user', 'channelName', 'about'],
'a'
);
}
} else {
$users[0]["email"] = $_POST['email'];
}
// send 100 emails at a time
$mailsLimit = 100;
$obj = new stdClass();
$obj->error = false;
$obj->msg = [];
$obj->message = $_POST['message'];
//Create a new PHPMailer instance
$mail = new \PHPMailer\PHPMailer\PHPMailer();
setSiteSendMessage($mail);
//Set who the message is to be sent from
$mail->setFrom($config->getContactEmail());
$mail->Subject = 'Message From Site ' . $config->getWebSiteTitle();
$mail->msgHTML($obj->message);
$count = 0;
$currentCount = 0;
foreach ($users as $value) {
if ($count % $mailsLimit === 0) {
if ($count !== 0) {
if (!$mail->send()) {
$obj->error = true;
$obj->msg[] = __("Message could not be sent") . " " . $mail->ErrorInfo;
}
$mail->ClearAddresses();
$mail->ClearCCs();
$mail->ClearBCCs();
$currentCount = 0;
}
}
$mail->addBCC($value["email"]);
$count++;
$currentCount++;
}
if ($currentCount && !$mail->send()) {
$obj->error = true;
$obj->msg[] = __("Message could not be sent") . " " . $mail->ErrorInfo;
}
$obj->count = $count;
echo json_encode($obj);