<?php require_once "header.php"; ?>
<h1>Email Finder</h1>
<form method="GET" action="" class="form-inline my-2 my-lg-0">
	Find : <input type="text" class="form-control mr-sm-2" name="domain" placeholder="<?php echo htmlentities($_GET['domain']) ?>"> 
	<input type="submit" class="btn btn-primary my-2 my-sm-0" value="Search">
</form>
<?php
error_reporting(0);
header("X-Frame-Options: DENY");
header("Content-Security-Policy: frame-ancestors 'none'", false);
$domain = $_GET['domain'];
if (isset($_GET['domain'])) {
	$domain = $_GET['domain'];
	function http_request($url){
	    $ch = curl_init();
	    curl_setopt($ch, CURLOPT_URL, $url);
	    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
	    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	    $output = curl_exec($ch); 
	    curl_close($ch);      
	    return $output;
	}

	$request = http_request("https://api.hunter.io/v2/domain-search?domain=".$domain."&api_key=7119e67fb9da1be75651d381c9fe66ee43e485d8");
	$request = json_decode($request);
	echo 'Total: '.count($request->data->emails).' Email<br/>
		<div style="color:#dbd9d9;"><table border="1" class="table">
		<tr>
			<th width=5><span style="color:black;">No</span></th>
			<th><span style="color:black;">Email</span></th>	
		</tr>';
	$nomor = 1;
	foreach ($request as $key => $value) {
		foreach ($value->emails as $key => $imel) {
			echo "<tr style='color:#dbd9d9;'>
					<td><span style='color:black;'>".$nomor++."</span></td>
					<td><a href='mailto:".htmlentities($imel->value)."' target='_blank'>".htmlentities($imel->value)."</a></td>
					</tr>";
		}
	}
}
?>
</div>
</body>
</html>