PHP Function Reference

PHP dns_get_mx() Function



The PHP dns_get_mx() function returns MX records corresponding to the specified internet host name. This function is an alias of getmxrr() function.

Syntax

dns_get_mx(hostname, mxhosts, weights)

Parameters

hostname Required. Specify the Internet host name.
mxhosts Required. A list of the MX records found is placed into the array mxhosts.
weights Optional. If the weights array is provided, it will be filled with the weight information gathered.

Return Value

Returns true if any records are found. Returns false if no records were found or if an error occurred.

Example:

The example below shows the usage of dns_get_mx() function.

<?php
$domain="alphacodingskills.com";

//getting the MX records
if(dns_get_mx($domain, $mx_details)){
  foreach($mx_details as $key => $value){
    echo "$key => $value \n";
  }
}
?>

The output of the above code will be:

0 => aspmx.l.google.com 
1 => alt1.aspmx.l.google.com 
2 => alt2.aspmx.l.google.com 
3 => alt4.aspmx.l.google.com 
4 => alt3.aspmx.l.google.com 

❮ PHP Network Reference

5