Example 1 — List MX Hosts with the Alias
Call dns_get_mx() and print the hosts array. The output is a typical fixed sample.
<?php
if (dns_get_mx("example.com", $mxhosts)) {
foreach ($mxhosts as $host) {
echo $host, PHP_EOL;
}
} else {
echo "No MX records", PHP_EOL;
} How It Works
- dns_get_mx() queries MX records for example. com.
- On success it fills $mxhosts by reference.
- The loop prints each mail host name.
- The two lines shown are typical sample values for teaching.

