-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmail.php
86 lines (70 loc) · 2.93 KB
/
mail.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
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
session_start();
require_once("conf.ini.php");
if (isset($_SESSION['logged_in']) && isset($_POST['subject'])) {
$subject = $_POST['subject'];
$message = $_POST['message'];
$connection = mysqli_connect("127.0.0.1", $username, $password, $database);
$query = mysqli_query($connection, "SELECT * FROM `users`;");
$recipients = [];
while ($row = mysqli_fetch_array($query)) {
$recipients[] = $row['email'];
}
$emails = [];
for ($i = 0; $i < sizeof($recipients); $i ++) {
$emails[(int) floor($i / 50)][] = $recipients[$i];
}
foreach ($emails as $email) {
$mail->clearAllRecipients();
$mail->setFrom('[email protected]', 'LAHS Hack Club');
$mail->addAddress('[email protected]', 'LAHS Hack Club');
foreach ($email as $user) {
$mail->addBCC($user);
}
$mail->isHTML(true);
$mail->Subject = $subject;
$mail->Body = "<head><link href='https://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'></head><body style='font-family: \"Roboto\", sans-serif;'><div style='width: 90%; height: 100%; padding: 5% 5%;'><div style='width: calc(100% - 20px); padding: 10px; background-color: #1565c0; color: white; text-align: center; font-size: 2em; margin: 0'>$subject</div><div style='background-color: #efefef; padding: 10px;'>$message</div></div></body>";
if (!$mail->send()) {
die('Mailer Error: '.$mail->ErrorInfo);
}
}
$slack_message = str_replace("</p><p>", "\n\n", $message);
$slack_message = str_replace("</p>\n<p>", "\n\n", $message);
$slack_message = str_replace("<p>", "", $slack_message);
$slack_message = str_replace("</p>", "", $slack_message);
$slack_message = str_replace("<b>", "*", $slack_message);
$slack_message = str_replace("</b>", "*", $slack_message);
$slack_message = str_replace("<em>", "_", $slack_message);
$slack_message = str_replace("</em>", "_", $slack_message);
$slack_message = str_replace("<br>", "\n", $slack_message);
$slack_message = str_replace("<br />", "\n", $slack_message);
$slack_message = preg_replace('/<[^>]*>/', "\n\n", $slack_message);
$url = 'https://slack.com/api/chat.postMessage';
$data = array(
'token' => $token,
'channel' => $announcements_channel,
'as_user' => 'true',
'parse' => 'full',
'mrkdwn' => 'true',
'attachments' => '[{
"fallback": "' . $subject . '",
"color": "#1565c0",
"pretext": "@everyone New announcement by the LAHS Hack Club staff: *' . $subject . '*",
"mrkdwn_in": ["pretext", "text"],
"text": "' . $slack_message . '",
"unfurl_links": "false",
"unfurl_media": "false",
"footer": "LAHS Hack Club Slack Bot"
}]'
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo "success";
}