Skip to content

Instantly share code, notes, and snippets.

@samilkorkmaz
Last active April 25, 2024 14:05
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 samilkorkmaz/0f82f9ab7f9e2b8cf501f92776a902af to your computer and use it in GitHub Desktop.
Save samilkorkmaz/0f82f9ab7f9e2b8cf501f92776a902af to your computer and use it in GitHub Desktop.
Display MX (Mail Exhange) records of a domain
<?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