-
Notifications
You must be signed in to change notification settings - Fork 40
/
test.php
executable file
·113 lines (103 loc) · 2.19 KB
/
test.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
108
109
110
111
112
113
<html>
<head><title>EMailqueue - Test</title></head>
<body>
<h1>EMailqueue - Test</h1>
<hr>
<?php
if (isset($_POST["action"]))
$action = $_POST["action"];
else
$action = "form";
switch ($action) {
case "send":
send();
break;
case "form":
form();
break;
}
function form() {
echo "
<form method=POST action=test.php>
<input type=hidden name=action value=send>
<p>
<b>API Key</b>
<input type=text name=key size=32>
</p>
<p>
<b>To email address</b>
<input type=text name=to size=60>
</p>
<p>
<b>From email address</b>
<input type=text name=from size=60 value=\"[email protected]\">
</p>
<p>
<b>Subject</b>
<input type=text name=subject size=80 value=\"Test subject\">
</p>
<p>
<b>Message</b><br>
<textarea name=message cols=80 rows=10>Test message</textarea>
</p>
<p>
<input type=submit value=\"Send\" />
</p>
</form>
";
}
function send() {
if (!$key = $_POST["key"]) {
echo "API key not specified";
return;
}
if (!$to = $_POST["to"]) {
echo "To email address not specified";
return;
}
if (!$from = $_POST["from"]) {
echo "From email address not specified";
return;
}
if (!$subject = $_POST["subject"]) {
echo "Subject not specified";
return;
}
if (!$message = $_POST["message"]) {
echo "Message not specified";
return;
}
$result = emailqueueApiCall(
"http://127.0.0.1/api/",
$key,
[
[
"from" => $from,
"to" => $to,
"subject" => $subject,
"content" => $message
]
]
);
if ($result["result"])
echo "Email queued into Emailqueue succesfully";
else
echo "Error queueing message into Emailqueue: ".$result["description"];
}
function emailqueueApiCall($endpoint, $key, $messages = false) {
$curl = curl_init();
$request = [
"key" => $key,
"messages" => $messages
];
curl_setopt($curl, CURLOPT_URL, $endpoint);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, ["q" => json_encode($request)]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result, true);
}
?>
</body>
</html>