forked from pulug/sfd17
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotify-me.php
executable file
·107 lines (84 loc) · 2.54 KB
/
notify-me.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
/*
This script handles AJAX requests from "Send me an email when it's done" form
and store emails in MailChimp subscribers list or in a file.
If you are going to use MailChimp you should change of $API_KEY and $LIST_ID
variables with your actual MailChimp API Key and List ID below
*/
// Set to "mailchimp" to store contacts in MailChimp or "file" to store in a file.
$STORE_MODE = "mailchimp";
// Your MailChimp API Key
$API_KEY = "cb6a20c0676b26b78e8f18f047b619a2-us8";
// Your MailChimp List ID
$LIST_ID = "6ffa2b9330";
/**********************************************************************************
All the work runs below
**********************************************************************************/
// Include MailChimp API
require('assets/lib/MailChimp.php');
// Allow only post method
if($_SERVER["REQUEST_METHOD"] == "POST" && !empty($_POST["email"])) {
$email = $_POST["email"];
// Send headers
header('HTTP/1.1 200 OK');
header('Status: 200 OK');
header('Content-type: application/json');
// Check if email is valid
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Store in a file
if ($STORE_MODE == "file") { // Store in a file
// Success
if(@file_put_contents($STORE_FILE, strtolower($email)."\r\n", FILE_APPEND)) {
echo json_encode(array(
"status" => "success"
));
// Error
} else {
echo json_encode(array(
"status" => "error",
"type" => "FileAccessError"
));
}
// Store in mailchimp
} elseif ($STORE_MODE == "mailchimp") { // Store with MailChimp
// Use MailChimp API to store
$MailChimp = new MailChimp($API_KEY);
$result = $MailChimp->call('lists/subscribe', array(
'id' => $LIST_ID,
'email' => array('email'=>$email),
'double_optin' => false,
'update_existing' => true,
'replace_interests' => false,
'send_welcome' => false,
));
// Create a response
// Success
if($result["email"] == $email) {
echo json_encode(array(
"status" => "success"
));
// Error
} else {
echo json_encode(array(
"status" => "error",
"type" => $result["name"]
));
}
// Error
} else {
echo json_encode(array(
"status" => "error",
));
}
// Error
} else {
echo json_encode(array(
"status" => "error",
"type" => "ValidationError"
));
}
} else {
header('HTTP/1.1 403 Forbidden');
header('Status: 403 Forbidden');
}
?>