-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempmaildetector.php
More file actions
40 lines (32 loc) · 1.12 KB
/
tempmaildetector.php
File metadata and controls
40 lines (32 loc) · 1.12 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
<?php
class Client {
private $apiKey;
private const API_URL = "https://api.tempmaildetector.com/check";
private const CONTENT_TYPE = "application/json";
public function __construct($apiKey) {
$this->apiKey = $apiKey;
}
public function checkDomain($domain) {
$requestBody = json_encode(["domain" => $domain]);
$headers = [
"Content-Type: " . self::CONTENT_TYPE,
"Authorization: " . $this->apiKey
];
$ch = curl_init(self::API_URL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestBody);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($ch);
if (curl_errno($ch)) {
throw new Exception('Request Error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode !== 200) {
throw new Exception("Received non-200 response: " . $response);
}
return json_decode($response, true);
}
}
?>