Skip to content

Instantly share code, notes, and snippets.

@pareshchouhan
Created December 22, 2017 06:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pareshchouhan/fadb83b78d96d93e563194afbd761905 to your computer and use it in GitHub Desktop.
Save pareshchouhan/fadb83b78d96d93e563194afbd761905 to your computer and use it in GitHub Desktop.
<?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