Net_DNS: Examples: MX Lookup

How to look up an MX record:

require_once("Net/DNS.php");
$res = new Net_DNS_Resolver();
$res->debug = 1;
$answer = $res->search("example.com", "MX");
echo "<BR><HR><BR>";
print_r($answer);

This example will query the name server and output the following:

;; search(example.com, MX, IN) ;; query(example.com, MX, IN) ;; using extended PHP sockets ;; send_udp(208.79.80.18:53): sending 29 bytes ;; timeout set to 5 seconds ;; answer from 208.79.80.18:53: 90 bytes ;; HEADER SECTION ;; id = 46468 ;; qr = 1 opcode = QUERY aa = 0 tc = 0 rd = 1 ;; ra = 1 rcode = NOERROR ;; qdcount = 1 ancount = 0 nscount = 1 arcount = 0 ;; QUESTION SECTION (1 record) ;; ;example.com. IN MX ;; ANSWER SECTION (0 records) ;; AUTHORITY SECTION (1 record) example.com. 1800 IN SOA dns1.icann.org. hostmaster.icann.org. 2011062844 7200 3600 1209600 3600 ;; ADDITIONAL SECTION (0 records)