note 25472 added to function.getmxrr

From: Date: Wed, 25 Sep 2002 02:39:44 +0000
Subject: note 25472 added to function.getmxrr
Groups: php.notes 
Request: Send a blank email to php-notes+get-37217@lists.php.net to get a copy of this message
I was pretty disappointed that the Win32 build of PHP doesn't incorporate getmxrr so, since I'm a naive newbie, I decided to hack together my own (and I stress hack). This has been tested on Win 2000 and Win XP. There's no reason this shouldn't work on Win NT but it will not work on Win 9x (you need the nslookup command). It will finish with the array $mx that will be a multidimensional array with the MX preference, host name and ip address. You can do a print_r ( $mx ) to see what it looks like. ----------------------------------------------- <?php $command = "nslookup -type=mx yahoo.com"; exec ( $command, $result ); $i = 0; while ( list ( $key, $value ) = each ( $result ) ) { if ( strstr ( $value, "mail exchanger" ) ) { $nslookup[$i] = $value; $i++; } } while ( list ( $key, $value ) = each ( $nslookup ) ) { $temp = explode ( " ", $value ); $mx[$key][0] = $temp[3]; $mx[$key][1] = $temp[7]; $mx[$key][2] = gethostbyname ( $temp[7] ); } array_multisort ( $mx ); ?> -- http://www.php.net/manual/en/function.getmxrr.php http://master.php.net/manage/user-notes.php?action=edit+25472 http://master.php.net/manage/user-notes.php?action=delete+25472 http://master.php.net/manage/user-notes.php?action=reject+25472

« previous php.notes (#37217) next »