PHP如何使用dns_get_mx()函数?

2021年3月26日16:13:28 发表评论 730 次浏览

dns_get_mx()函数是PHP中的内置函数, 它返回指定Internet主机名的MX记录。此功能是getmxrr()功能。

语法如下:

bool dns_get_mx( $host, $mxhosts, $weight );

参数:此函数接受上述和以下描述的三个参数:

  • $ host:它是必填参数。它指定要查找其MX记录的主机名。
  • $ mxhosts:它是必填参数。一个数组指定找到的MX主机名。
  • 重量:它是可选参数。填充了重量信息的数组。

返回值:如果找到任何记录, 则此函数返回TRUE, 否则返回FALSE。

注意:此功能可用于PHP 5.0.0和更高版本。

下面的程序说明了dns_get_mx()函数在PHP中:

程序1:

<?php
  
$domain = "lsbin.org" ;
  
if (dns_get_mx( $domain , $mx_details )) {
     foreach ( $mx_details as $key => $value ) {
         echo "$key => $value <br>" ;
     }
}
?>

输出如下:

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

程式2:

<?php
  
$domain = "yahoo.com" ;
  
if (dns_get_mx( $domain , $mx_details )) {
     foreach ( $mx_details as $key => $value ) {
         echo "$key => $value <br>" ;
     }
}
?>

输出如下:

0 => mta5.am0.yahoodns.net 
1 => mta6.am0.yahoodns.net 
2 => mta7.am0.yahoodns.net

参考: https://www.php.net/manual/en/function.dns-get-mx.php


木子山

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: