-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathform.php
executable file
·49 lines (35 loc) · 1.3 KB
/
form.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
<?php
header('Content-type: application/json');
function join_listserv($email) {
$headers = 'From: ' . $email;
if(mail("[email protected]","join","join",$headers)) {
return Array('success' => TRUE, 'email' => $email);
} else {
return Array('success' => FALSE,'error' => 'Doh! PHP\'s mail() function failed for some reason. Try again later?');
}
}
function send_hello($name, $email, $message) {
$headers = 'From: ' . $email;
if(mail("[email protected]", "Message from " . $name, $message, $headers)) {
return Array('success'=>TRUE);
} else {
return Array('success'=>FALSE,'error'=>'Doh! PHP\'s mail() function failed for some reason. Try again later?');
}
}
if (isset($_POST['type'])) {
$resp = '';
if ($_POST['type'] == 'join' && isset($_POST['email'])) {
$resp = join_listserv($_POST['email']);
} elseif ($_POST['type'] == 'message' && isset($_POST['name']) && isset($_POST['email']) && isset($_POST['message'])) {
$resp = send_hello($_POST['name'], $_POST['email'], $_POST['message']);
//If also joining listserv
if ($_POST['join']) {
$resp2 = join_listserv($_POST['email']);
//Check if either one failed
$resp['success'] = ($resp['success'] && $resp2['success']);
$resp['email'] = $resp2['email'];
}
}
echo(json_encode($resp));
}
?>