forked from kolomanschaft/slack-mailer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailinglist.php
45 lines (34 loc) · 1.08 KB
/
mailinglist.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
<?php
// Configuration
// ============================================================
// Take this token from slack's webhook integration settings
$slack_token = "<paste-the-token-here>";
// The slack user who wrote the post (comes from Slack)
$slack_user = $_POST["user_name"];
// The text of the posted message (comes from Slack)
$slack_msg = $_POST["text"];
// Recipient of the emails
$to = "Frank Sinatra <[email protected]>";
// From-header in the emails
$from = $slack_user." via Slack <[email protected]>";
// Reply-to address in the emails
$reply_to = $from;
// Subject of the emails
$subject = "@".$slack_user." wrote";
// ============================================================
// Setting up headers
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=utf8";
$headers[] = "From: ".$from;
$headers[] = "Reply-To: ".$reply_to;
$headers[] = "X-Mailer: PHP/".phpversion();
// Send!
if ($_POST["token"] == $slack_token)
{
if (!mail($to, $subject, $slack_msg, implode("\r\n", $headers)))
{
echo "failed to send!";
}
}
?>