forked from thepieterdc/mailinator-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMailinator.php
More file actions
65 lines (53 loc) · 1.53 KB
/
Copy pathMailinator.php
File metadata and controls
65 lines (53 loc) · 1.53 KB
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
<?php
class Mailinator
{
private $token;
private $apiEndpoint = "https://api.mailinator.com/api/";
private $inboxCount = 0;
public function __construct($token)
{
$this->token = $token;
}
private function call($method, $params)
{
$ch = curl_init();
$callback_parameters = http_build_query(array_merge($params, array('token' => $this->token)),'', '&');
curl_setopt($ch, CURLOPT_URL, $this->apiEndpoint . $method . '?' . $callback_parameters);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$exec = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
if($info["http_code"] == 200)
{
return json_decode($exec, true);
}
else
{
throw new Exception('There was an error contacting the mailinator API endpoint. The HTTP status code returned was: ' . $info["http_code"] );
}
}
public function fetchInbox($inbox)
{
$query = $this->call('inbox', array('to' => $inbox));
if(!isset($query["messages"]))
{
throw new Exception('Missing messages data in response from mailinator API.');
}
$this->inboxCount = count($query["messages"]);
return $query["messages"];
}
public function fetchMail($msgId)
{
$query = $this->call('email', array('id' => $msgId));
if(!isset($query["data"]))
{
throw new Exception('Missing data in response from mailinator API.');
}
return $query["data"];
}
}
?>