Created
December 22, 2017 06:02
-
-
Save pareshchouhan/fadb83b78d96d93e563194afbd761905 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Dns { | |
public $hostname; | |
public $txt; | |
public $spf; | |
public $dkim; | |
public $dkimTxt; | |
public $dkimSelector; | |
public function __construct($hostname, $dkimSelector) { | |
//fetch DNS TXT records for now | |
$this->hostname = $hostname; | |
$this->dkimSelector = $dkimSelector; | |
$this->txt = dns_get_record($hostname, DNS_TXT); | |
$this->dkimTxt = dns_get_record($dkimSelector.'._domainkey.'.$hostname, DNS_TXT); | |
$this->_parseSPFAndDKIMRecords(); | |
} | |
private function _parseSPFAndDKIMRecords() { | |
// echo '<pre>'; | |
// print_r($this->txt); | |
// print_r($this->dkimTxt); | |
// echo '</pre>'; | |
if(isset($this->txt) && !empty($this->txt)) { | |
foreach($this->txt as $txtRecordIndex => $txtRecord) { | |
if(strpos($txtRecord['txt'], 'spf')) { | |
$this->spf = $txtRecord['txt']; | |
continue; | |
} | |
} | |
} | |
if(isset($this->dkimTxt) && !empty($this->dkimTxt)) { | |
foreach($this->dkimTxt as $txtRecordIndex => $txtRecord) { | |
if(strpos($txtRecord['host'], '_domainkey')) { | |
$this->dkim = $txtRecord['txt']; | |
continue; | |
} | |
} | |
} | |
} | |
public function checkSPF($spf) { | |
return $this->spf == $spf ? "✓" : "❌";; | |
} | |
public function checkDKIM($dkim) { | |
return $this->dkim == $dkim ? "✓" : "❌"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment