Last active
April 25, 2024 14:05
-
-
Save samilkorkmaz/0f82f9ab7f9e2b8cf501f92776a902af to your computer and use it in GitHub Desktop.
Display MX (Mail Exhange) records of a domain
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 | |
// Online tool: https://mxtoolbox.com/ | |
function getMXRecords($domain) { | |
$mxhosts = []; | |
$weights = []; | |
// Get MX records associated with the domain | |
if (getmxrr($domain, $mxhosts, $weights)) { | |
$mxRecords = array_combine($mxhosts, $weights); | |
asort($mxRecords); // Sort by weight | |
return $mxRecords; | |
} else { | |
return false; // No MX records found | |
} | |
} | |
function show($domain) { | |
$mxRecords = getMXRecords($domain); | |
if ($mxRecords) { | |
echo "MX Records for $domain:\n"; | |
foreach ($mxRecords as $host => $weight) { | |
echo "Host: $host, Priority: $weight\n"; | |
} | |
} else { | |
echo "No MX records found for $domain."; | |
} | |
} | |
show("your domain 1"); | |
echo "\n"; | |
show("your domain 2"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment