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.


dns_get_mx(hostname, mxhosts, weights)


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.


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


//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 => 
1 => 
2 => 
3 => 
4 => 

❮ PHP Network Reference