Skip to content

Commit

Permalink
Added IPv6 support
Browse files Browse the repository at this point in the history
  • Loading branch information
spartas committed Mar 12, 2014
1 parent 2de3c80 commit f0ad450
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions verify.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
print_r(verifyEmail('[email protected]', '[email protected]', true));

function verifyEmail($toemail, $fromemail, $getdetails = false){
$email_arr = explode("@", $toemail);
$domain = array_slice($email_arr, -1);
Expand All @@ -10,6 +8,10 @@ function verifyEmail($toemail, $fromemail, $getdetails = false){
$domain = ltrim($domain, "[");
$domain = rtrim($domain, "]");

if( "IPv6:" == substr($domain, 0, strlen("IPv6:")) ) {
$domain = substr($domain, strlen("IPv6") + 1);
}

$mxhosts = array();
if( filter_var($domain, FILTER_VALIDATE_IP) )
$mx_ip = $domain;
Expand All @@ -19,7 +21,13 @@ function verifyEmail($toemail, $fromemail, $getdetails = false){
if(!empty($mxhosts) )
$mx_ip = $mxhosts[array_search(min($mxweight), $mxhosts)];
else {
$record_a = dns_get_record($domain, DNS_A);
if( filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) ) {
$record_a = dns_get_record($domain, DNS_A);
}
elseif( filter_var($domain, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) ) {
$record_a = dns_get_record($domain, DNS_AAAA);
}

if( !empty($record_a) )
$mx_ip = $record_a[0]['ip'];
else {
Expand Down

0 comments on commit f0ad450

Please sign in to comment.