<?php $hostname = "google.com"; if(dns_get_mx($hostname, $mxhosts, $weights)) { foreach($mxhosts as $key => $host) { echo "Hostname: $host (Weight: {$weights[$key]}<BR/>\n"; } } else { echo "Could not find any MX records for $hostname\n"; } ?>