You are here

function win_getmxrr in Email Verify 8.2

Same name and namespace in other branches
  1. 6 windows_compat.inc \win_getmxrr()
  2. 7.2 windows_compat.inc \win_getmxrr()
  3. 7 windows_compat.inc \win_getmxrr()

getmxrr() support for Windows prior to PHP 5.3.0 by HM2K <php [at] hm2k.org>.

Parameters

string $hostname: The Internet host name.

array $mxhosts: A list of the MX records found is placed into the array mxhosts.

array $mxweight: If the weight array is given, it will be filled with the weight information gathered.

Return value

boolean Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred.

See also

http://php.net/manual/function.getmxrr.php#88033

1 call to win_getmxrr()
windows_compat.inc in ./windows_compat.inc

File

./windows_compat.inc, line 33

Code

function win_getmxrr($hostname, &$mxhosts, &$mxweight = FALSE) {
  if (empty($hostname)) {
    return;
  }
  if (strtoupper(substr(PHP_OS, 0, 3)) != 'WIN') {
    return;
  }
  if (!is_array($mxhosts)) {
    $mxhosts = array();
  }
  $exec = 'nslookup -type=MX ' . escapeshellarg($hostname);
  @exec($exec, $output);
  if (empty($output)) {
    return;
  }
  $i = -1;
  foreach ($output as $line) {
    $i++;
    if (preg_match("/^{$hostname}\tMX preference = ([0-9]+), mail exchanger = (.+)\$/i", $line, $parts)) {
      $mxweight[$i] = trim($parts[1]);
      $mxhosts[$i] = trim($parts[2]);
    }
    if (preg_match('/responsible mail addr = (.+)$/i', $line, $parts)) {
      $mxweight[$i] = $i;
      $mxhosts[$i] = trim($parts[1]);
    }
  }
  return $i != -1;
}