How to use the dns_get_mx() function to get MX records for host name in PHP

2 Answers

0 votes
$hostname = "yahoo.com";
if (dns_get_mx($hostname, $mxhosts, $weight)) {

    foreach ($mxhosts as $key => $host) 
        echo "Hostname: $host - Weight: {$weight[$key]}<br />";
}
else
    echo "MX records not found";


/*
run:

Hostname: mta5.am0.yahoodns.net - Weight: 1
Hostname: mta6.am0.yahoodns.net - Weight: 1
Hostname: mta7.am0.yahoodns.net - Weight: 1

*/

 



answered Oct 7, 2016 by avibootz
edited Oct 7, 2016 by avibootz
0 votes
$hostname = "facebook.com";
if (dns_get_mx($hostname, $mxhosts, $weight)) {
 
    foreach ($mxhosts as $key => $host) 
        echo "Hostname: $host - Weight: {$weight[$key]}<br />";
}
else
    echo "MX records not found";
 
 
/*
run:
 
Hostname: msgin.vvv.facebook.com - Weight: 10
 
*/

 



answered Oct 7, 2016 by avibootz
...