-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathexample_api.php
executable file
·44 lines (38 loc) · 1.13 KB
/
example_api.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
<html>
<head><title>EMailqueue - API example</title></head>
<body>
<h1>EMailqueue - API example</h1>
<h2>An example on how inject emails to Emailqueue by calling Emailqueue's API. This is the method to use when Emailqueue is installed in another server, or in a dockerized environment.</h2>
<hr>
<?php
$result = emailqueueApiCall(
"http://127.0.0.1/api/",
"asfKkj3=m2345k",
[
[
"from" => "[email protected]",
"to" => "[email protected]",
"sender" => "[email protected]",
"subject" => "Just testing",
"content" => "This is just an email to test Emailqueue"
]
]
);
echo "<b>Api call result:</b><br><pre>".print_r($result, true)."</pre>";
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>