Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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