|
|
 |
getmxrr (PHP 3, PHP 4, PHP 5) getmxrr --
Obtener los registros MX correspondientes a un nombre de host de
Internet dado
Descripciónbool getmxrr ( string nombre_host, array &hosts_mx [, array &peso] )
Busca en DNS por registros MX correspondientes a
nombre_host. Devuelve TRUE si se
encuentran registros; devuelve FALSE si no se encuentran
registros o si ocurre un error.
Una lista de los registros MX encontrados es colocada en la
matriz hosts_mx. Si la matriz
peso es definida, será llenada con
la información de peso recolectada.
Nota:
Esta función no debe ser usada para propósitos de
verificación de direcciones. Solo los puntos de
intercambio de correo en DNS son devueltos, sin embargo, de
acuerdo a RFC 2821, cuando
no se listan puntos de intercambio de correo,
nombre_host mismo deberÃa ser
usado como el único punto de intercambio de correo con
una prioridad de 0.
Nota:
Esta función no es implementada en plataformas
Windows. Intente la clase de PEAR Net_DNS.
Vea también checkdnsrr(),
dns_get_record(),
gethostbyname(),
gethostbynamel(),
gethostbyaddr(), y la página de manual
para named(8).
choward AT fast DOT net DOT NO SPAM PLZ
12-Apr-2006 12:32
Below Code Used and edited from -ng4rrjanbiah at rediffmail dot com- posted note.
Testing on Windows 2000 Advanced Server.
PHP v4.4.1
function getmxrr($hostname, &$mxhosts)
{
$mxhosts = array();
exec('%SYSTEMDIRECTORY%\\nslookup.exe -q=mx '.$hostname, $result_arr);
foreach($result_arr as $line)
{
if (preg_match("/.*mail exchanger = (.*)/", $line, $matches))
$mxhosts[] = $matches[1];
}
return( count($mxhosts) > 0 );
}//--End of workaround
//test..
getmxrr('yahoo.com', $mxhosts);
print_r($mxhosts);
As you can see the only thing i had to do in order to make this work was add a direct path to nslookup and add the .exe extension. You can use either the "Type" or "Q" parameter, both worked for me. I am not sure as to why the inital script failed... Safe Mode is on, but that is not the culprit. If i look into it and find an answer i will post it. My initial thoughts are that the SystmDir and WinDir Environment Vars are set to C:\WINNT when i would think SystemDir is actually supposed to be C:\WINNT\System32 for windows systems... but i also think that because C:\WINNT\System32 is in my Windows OS Environmental Var PATH that it shouldn't matter so i am not sure why i had to put in the whole path, but either way it now works. If anyone has some insight or simply wants to point me to something i can read, that'd be much appreciated as i will probably not think about this issue again... Especially since this particular system has had way too many changes to it and programs installed etc... it is an all around test unit. The issue may be mine alone, but i thought i would post this in hopes of saving someone time just in case.
Lennart Poot(www.twing.nl)
07-Apr-2006 12:23
This script validates an e-mail adress using getmxrr and fsockopen
1. it validates the syntax of the address.
2. get MX records by hostname
3. connect mail server and verify mailbox(using smtp command RCTP TO:<email>)
When the function "validate_email([email])" fails connecting the mail server with the highest priority in the MX record it will continue with the second mail server and so on..
The function "validate_email([email])" returns 0 when it failes one the 3 steps above, it will return 1 otherwise
Grtz Lennart Poot
<?
function validate_email($email){
$mailparts=explode("@",$email);
$hostname = $mailparts[1];
$exp = "^[a-z\'0-9]+([._-][a-z\'0-9]+)*@([a-z0-9]+([._-][a-z0-9]+))+$";
$b_valid_syntax=eregi($exp, $email);
$b_mx_avail=getmxrr( $hostname, $mx_records, $mx_weight );
$b_server_found=0;
if($b_valid_syntax && $b_mx_avail){
$mxs=array();
for($i=0;$i<count($mx_records);$i++){
$mxs[$mx_weight[$i]]=$mx_records[$i];
}
ksort ($mxs, SORT_NUMERIC );
reset ($mxs);
while (list ($mx_weight, $mx_host) = each ($mxs) ) {
if($b_server_found == 0){
$fp = @fsockopen($mx_host,25, $errno, $errstr, 2);
if($fp){
$ms_resp="";
$ms_resp.=send_command($fp, "HELO microsoft.com");
$ms_resp.=send_command($fp, "MAIL FROM:<support@microsoft.com>");
$rcpt_text=send_command($fp, "RCPT TO:<".$email.">");
$ms_resp.=$rcpt_text;
if(substr( $rcpt_text, 0, 3) == "250")
$b_server_found=1;
$ms_resp.=send_command($fp, "QUIT");
fclose($fp);
}
}
}
}
return $b_server_found;
}
function send_command($fp, $out){
fwrite($fp, $out . "\r\n");
return get_data($fp);
}
function get_data($fp){
$s="";
stream_set_timeout($fp, 2);
for($i=0;$i<2;$i++)
$s.=fgets($fp, 1024);
return $s;
}
if (!function_exists ('getmxrr') ) {
function getmxrr($hostname, &$mxhosts, &$mxweight) {
if (!is_array ($mxhosts) ) {
$mxhosts = array ();
}
if (!empty ($hostname) ) {
$output = "";
@exec ("nslookup.exe -type=MX $hostname.", $output);
$imx=-1;
foreach ($output as $line) {
$imx++;
$parts = "";
if (preg_match ("/^$hostname\tMX preference = ([0-9]+), mail exchanger = (.*)$/", $line, $parts) ) {
$mxweight[$imx] = $parts[1];
$mxhosts[$imx] = $parts[2];
}
}
return ($imx!=-1);
}
return false;
}
}
?>
jeff at pzenix dot com
08-Mar-2006 09:58
I should point out that the below example won't work with some domains (.co.uk, .org.uk, .net.uk for example) because it assumes (possibly incorrectly) that the format is [ DOMAIN ].[ EXT ].
off at NOSPAM dot abwesend dot de
11-Feb-2006 07:18
Concerning the message by 'rolf at rowi dot net' (do a check on a address containing a subdomain) we could use:
$email = 'abc@etpc01.trier.fh-rpl.de';
$strDot = '.';
$strAfterAt = substr(strstr($email, '@'), 1);
$chunks = explode($strDot, $strAfterAt);
$cntChunks = count($chunks) - 1;
$strDomain = $chunks[($cntChunks-1)] . $strDot . $chunks[$cntChunks];
if (!getmxrr( $strDomain, $mxhosts )) {
echo 'Mailserver not found';
}
// $strDomain is set to 'fh-rpl.de';
richard dot quadling at bandvulc dot co dot uk
25-May-2005 02:04
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.
rune dot heggtveit at devzone dot progative dot com
23-Jan-2005 01:02
An other way to do mx-lookup on a windows platform.
Rewrote this from an other class i wrote for DNS lookup - so it might be a bit messy - but hope you get the idea.
Big thanks to the rfc community.
<?php
class mxlookup
{
var $dns_socket = NULL;
var $QNAME = "";
var $dns_packet= NULL;
var $ANCOUNT = 0;
var $cIx = 0;
var $dns_repl_domain;
var $arrMX = array();
function mxlookup($domain, $dns="192.168.2.1")
{
$this->QNAME($domain);
$this->pack_dns_packet();
$dns_socket = fsockopen("udp://$dns", 53);
fwrite($dns_socket,$this->dns_packet,strlen($this->dns_packet));
$this->dns_reply = fread($dns_socket,1);
$bytes = stream_get_meta_data($dns_socket);
$this->dns_reply .= fread($dns_socket,$bytes['unread_bytes']);
fclose($dns_socket);
$this->cIx=6;
$this->ANCOUNT = $this->gord(2);
$this->cIx+=4;
$this->parse_data($this->dns_repl_domain);
$this->cIx+=7;
for($ic=1;$ic<=$this->ANCOUNT;$ic++)
{
$QTYPE = ord($this->gdi($this->cIx));
if($QTYPE!==15){print("[MX Record not returned]"); die();}
$this->cIx+=9;
$mxPref = ord($this->gdi($this->cIx));
$this->parse_data($curmx);
$this->arrMX[] = array("MX_Pref" => $mxPref, "MX" => $curmx);
$this->cIx+=3;
}
}
function parse_data(&$retval)
{
$arName = array();
$byte = ord($this->gdi($this->cIx));
while($byte!==0)
{
if($byte==192) {
$tmpIx = $this->cIx;
$this->cIx = ord($this->gdi($cIx));
$tmpName = $retval;
$this->parse_data($tmpName);
$retval=$retval.".".$tmpName;
$this->cIx = $tmpIx+1;
return;
}
$retval="";
$bCount = $byte;
for($b=0;$b<$bCount;$b++)
{
$retval .= $this->gdi($this->cIx);
}
$arName[]=$retval;
$byte = ord($this->gdi($this->cIx));
}
$retval=join(".",$arName);
}
function gdi(&$cIx,$bytes=1)
{
$this->cIx++;
return(substr($this->dns_reply, $this->cIx-1, $bytes));
}
function QNAME($domain)
{
$dot_pos = 0; $temp = "";
while($dot_pos=strpos($domain,"."))
{
$temp = substr($domain,0,$dot_pos);
$domain = substr($domain,$dot_pos+1);
$this->QNAME .= chr(strlen($temp)).$temp;
}
$this->QNAME .= chr(strlen($domain)).$domain.chr(0);
}
function gord($ln=1)
{
$reply="";
for($i=0;$i<$ln;$i++){
$reply.=ord(substr($this->dns_reply,$this->cIx,1));
$this->cIx++;
}
return $reply;
}
function pack_dns_packet()
{
$this->dns_packet = chr(0).chr(1).
chr(1).chr(0).
chr(0).chr(1).
chr(0).chr(0).
chr(0).chr(0).
chr(0).chr(0).
$this->QNAME.
chr(0).chr(15).
chr(0).chr(1);
}
}
?>
<?php
$mx = new mxlookup("php.net");
print $mx->ANCOUNT." MX Records\n";
print "Records returned for ".$mx->dns_repl_domain.":\n<pre>";
print_r($mx->arrMX);
?>
Return:
02 MX Records Records returned for php.net:
Array
(
[0] => Array
(
[MX_Pref] => 15
[MX] => smtp.osuosl.org
)
[1] => Array
(
[MX_Pref] => 5
[MX] => osu1.php.net
)
)
rolf at rowi dot net
21-Jan-2005 06:36
Be aware that not just user@example.com ist a valid address, also user@subnet.example.com is valid (but maybe less common). Just got into trouble with this check...
Rolf
siclawrence at gmail dot com
04-Jan-2005 06:43
This code replicates online tools that let you check if an email address is valid. First it checks if the email format is correct, then looks up and prints the mx records. All nicely formatted with fancy words that in the end prints whether the email address valid or invalid.
<?php
$email = "email@domain.com";
print("Checking: $email<br>");
if (eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)+$", $email)) {
print("Format Test: PASSED<br>");
print("Online host verification Test...<br><br>");
print("MX Records for: $email<br>");
list($alias, $domain) = split("@", $email);
if (checkdnsrr($domain, "MX")) {
getmxrr($domain, $mxhosts);
foreach($mxhosts as $mxKey => $mxValue){
print(" $mxValue<br>");
}
print("Online host verification Test: PASSED<br><br>");
print("Email Status: VALID");
} else {
print(" No records found.<br>");
print("Online host verification Test: FAILED<br><br>");
print("Email Status: INVALID");
}
} else {
print("Format Test: FAILED<br><br>");
print("Invalid email address provided.<br><br>");
print("Email Status: INVALID");
}
?>
zorlac_man at hotmail dot com
14-May-2004 12:15
For some reason this and the other DNS lookup functions seem to be really slow on my Linux box. I've checked several things and have no explanation.
As a work-around, I gave in and just used a system call to dig:
<?php
CheckMX("fakedomain.org");
CheckMX("hotmail.com");
function CheckMX($domain) {
exec("dig +short MX " . escapeshellarg($domain),$ips);
if($ips[0] == "") {
print "MX record found for $domain not found!\n";
return FALSE;
}
print "MX Record for $domain found\n";
return TRUE;
}
?>
Output:
MX record found for fakedomain.org not found!
MX Record for hotmail.com found
As someone else pointed out, it is prudent to check to see if the TLD has an IP address if the MX record is not found.
ng4rrjanbiah at rediffmail dot com
26-Feb-2004 03:11
Here is a better workaround for Windows platform. Tested on Windows XP. Highly impressed by "geoffbrisbine A T y a h o o DOT c o m"'s idea of nslookup usage.
<?php
function getmxrr($hostname, &$mxhosts)
{
$mxhosts = array();
exec('nslookup -type=mx '.$hostname, $result_arr);
foreach($result_arr as $line)
{
if (preg_match("/.*mail exchanger = (.*)/", $line, $matches))
$mxhosts[] = $matches[1];
}
return( count($mxhosts) > 0 );
}echo getmxrr('yahoo.com', $mxhosts);
print_r($mxhosts);
?>
HTH,
R. Rajesh Jeba Anbiah
geoffbrisbine A T y a h o o DOT c o m
24-Sep-2002 09:39
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 );
?>
paul at start dot co dot uk
16-Jan-2001 12:48
Prevent your dns server from 'creating' a valid host name by appending the local domain to incomplete emails by appending to the domain a trailing . both in the pattern match and mx checks:
if (eregi("^[0-9a-z_]([-_.]?[0-9a-z])*@[0-9a-z][-.0-9a-z]*\\.[a-z]{2,3}[.]?$", $string, $check)) {
$host = substr(strstr($check[0], '@'), 1).".";
if ( getmxrr($host, $validate_email_temp) )
return TRUE;
// THIS WILL CATCH DNSs THAT ARE NOT MX.
if(checkdnsrr($host,"ANY"))
return TRUE;
}
return FALSE;
| |
| | Citas célebres | Se debe hacer todo tan sencillo como sea posible, pero no más sencillo. Albert Einstein Físico estadounidense (1879-1955) | | Citas en tu mail | | ©Contenidos Gratis |
| Chiste de... Médicos | | Estupenda | En un chequeo médico de empresa:
- A ver señorita, desnúdese por completo.
- Pero si otro colega suyo me ha reconocido hace cinco minutos y me ha dicho que estoy estupenda.
- A mí también me lo ha dicho, por eso quiero comprobarlo. | | Chistes en tu mail | | ©ContenidosGratis |
| Inicio | Acción | Estrategia | Palabras | Puzzles | Solitarios | Foro Trucos |  | Cake Mania Jugadores: 6835 Categoría del juego: Acción Objetivo del juego: Ayuda a Jill a recuperar la pastelería de su abuela llevando su propia pastelería; consigue clientes y gana dinero. |
|  | Rainbow Web Jugadores: 2199 Categoría del juego: Puzzles Objetivo del juego: Rompe un pegajoso hechizo y salva un reino de fantasía en Rainbow Web. Tendrás toneladas de diversión mientras juegas a este mágico desafío para la mente. |
|  | Mahjongg Fortuna Jugadores: 12462 Categoría del juego: Solitarios Objetivo del juego: Velocidad y habilidad mental son las armas más importantes en esta versión de un antiguo juego asiático. Despeja el tablero lo antes posible haciendo clic en las fichas iguales y gánate la fama eterna de la puntuación más alta. |
|  | Chainz 2 Jugadores: 6955 Categoría del juego: Puzzles Objetivo del juego: Entra en el mundo de las combinaciones con Chainz 2: Relinked, emocionante secuela del exitazo del año pasado, Chainz. Gira eslabones y crea combinaciones de 3 ó más. |
|  | Delicious Jugadores: 4405 Categoría del juego: Acción Objetivo del juego: ¿Eres un as de la multitarea? ¿Quieres que tus clientes estén contentos? ¡Pues Delicious es tu juego! Sacia el apetito de los clientes y tenlos contentos; ¡no te arriesgues! |
|  | Bookworm Jugadores: 4568 Categoría del juego: Palabras Objetivo del juego: Junta las letras para formar palabras. ¡Las palabras más largas valen más puntos! |
|  | Zuma Jugadores: 4976 Categoría del juego: Acción Objetivo del juego: Controla el ídolo de la rana de piedra de los antiguos Zuma en este intrigante enigma de acción. ¡Dispara bolas para formar conjuntos de tres, pero si dejas que lleguen a la calavera dorada morirás! |
|  | Jewel of Atlantis Jugadores: 3798 Categoría del juego: Puzzles Objetivo del juego: Descubre la ciudad hundida de la Atlántida y busca valiosos tesoros. Viaja más allá de las profundidades del mar y vive trepidantes aventuras en Jewel of Atlantis. |
|  | Jewel Quest Jugadores: 3727 Categoría del juego: Puzzles Objetivo del juego: Convierte la arena de la antigua selva en oro tan rápido como puedas juntando grupos de 3 elementos. ¡Los grupos más grandes valen más puntos! |
|  | Bejeweled 2 Jugadores: 3659 Categoría del juego: Puzzles Objetivo del juego: Con cuatro modos de juego únicos y fascinantes, nuevas piezas de juego explosivas e imponentes fondos planetarios, Bejeweled 2 es mucho más adictivo que nunca. |
|
|