note 53182 modified in function.getmxrr by rquadling
| From: | rquadling@php.net | Date: | Tue, 29 May 2007 11:02:14 +0000 |
| Subject: | note 53182 modified in function.getmxrr by rquadling | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126991@lists.php.net to get a copy of this message | ||
Windows alternative for getmxrr without the need for PEAR.
<?php
define('DEFAULT_GATEWAY', 'nnn.nnn.nnn.nnn');
if (!function_exists('getmxrr'))
{
/*
This function is a replacement for the missing Windows function getmxrr.
The parameters are the same as those for the normal getmxrr function.
The steps this function takes are :
1 - Use NSLOOKUP.EXE to get the MX records for the supplied Host.
2 - Use regular expressions to extract the mail servers and the preference.
3 - Sort the results by preference.
4 - Set the return arrays.
5 - Return true or false.
*/
function getmxrr($s_HostName, array &$a_MXHosts = NULL, array &$a_Weights = NULL)
{
// Simulate all the required network activity by executing windows' NSLOOKUP.
$s_NSLookup = shell_exec("nslookup -q=mx {$s_HostName} 2>nul");
preg_match_all("'^.*MX preference = (\d{1,10}), mail exchanger = (.*)$'simU",
$s_NSLookup, $a_MXMatches);
// If there is something to return ...
if (count($a_MXMatches[2]) > 0)
{
// Produce output arrays if they have been requested.
$i_ArgCount = func_num_args();
if ($i_ArgCount > 1)
{
array_multisort($a_MXMatches[1], $a_MXMatches[2]);
switch ($i_ArgCount)
{
case 3 :
$a_Weights = $a_MXMatches[1];
case 2 :
$a_MXHosts = $a_MXMatches[2];
}
}
return True;
}
else
{
return False;
}
}
}
?>
You will need to know your default gateway (either it's IP address or its name).
To do this, run the program IPCONFIG /ALL at a cmd prompt and look for the Default Gateway.
Then replace the 'nnn.nnn.nnn.nnn' with the address.
Richard.
--was--
Windows alternative for getmxrr without the need for PEAR.
define('DEFAULT_GATEWAY', 'nnn.nnn.nnn.nnn');
function raqgetmxrr($sHostName, &$aMXHosts, &$aWeights = NULL)
{
/*
This function is a replacement for the missing Windows function getmxrr.
The parameters are the same as those for the normal getmxrr function.
The steps this function takes are :
1 - Use NSLOOKUP.EXE to get the MX records for the supplied Host.
2 - Use regular expressions to extract the mail servers and the preference.
3 - Sort the results by preference.
4 - Set the return arrays.
5 - Return true or false.
*/
$sNSLookup = shell_exec("nslookup -q=mx {$sHostName} DEFAULT_GATEWAY 2>nul");
preg_match_all("'^.*MX preference = (\d{1,10}), mail exchanger = (.*)$'simU",
$sNSLookup, $aMXMatches);
if (count($aMXMatches[2]) > 0)
{
array_multisort($aMXMatches[1], $aMXMatches[2]);
$aMXHosts = $aMXMatches[2];
if (!is_null($aWeights))
{
$aWeights = $aMXMatches[1];
}
return True;
}
else
{
return False;
}
}
You will need to know your default gateway (either it's IP address or its name).
To do this, run the program IPCONFIG /ALL at a cmd prompt and look for the Default Gateway.
Then replace the 'nnn.nnn.nnn.nnn' with the address.
Richard.
http://php.net/manual/en/function.getmxrr.php