Newsgroup: it.comp.www.php
Titolo: riconoscimento e-mail [in particolare per Setec Astronomy]

Qualche giorno fa, Setec aveva suggerito questo script per vedere se
un'e-mail è vera o falsa
<?php
define ('DEBUG_OK', false);
Class CSmtp
{
var $timeout = 10;
function checkmail ($email = "")
{
$host = substr (strstr ($email, '@'), 1, 255) . ".";
if (getmxrr ($host, $mxhosts[0],  $mxhosts[1]) == true)
{ array_multisort ($mxhosts[1],  $mxhosts[0]); }
else
{
$mxhosts[0] = $host;
$mxhosts[1] = 10;
}
if (DEBUG_OK) { print_r ($mxhosts); }
$port = 25;
$error = '';
$localhost = '
libero.it
';
$sender = 'info@' . $localhost;
$result = false;
$id = 0;
while (!$result && $id < count($mxhosts[0]))
{
if (function_exists ("fsockopen"))
{
if (DEBUG_OK) { print_r ($id . " " . $mxhosts[0][$id]); }
if ($connection = fsockopen ($mxhosts[0][$id], $port, $errno,
$error, $this->timeout))
{
fputs ($connection,"HELO $localhost\r\n"); // 250
$data = fgets ($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ 
fputs ($connection,"MAIL FROM:<$sender>\r\n");
$data = fgets($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ 
fputs ($connection,"RCPT TO:<$email>\r\n");
$data = fgets($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ 
fputs ($connection,"data\r\n");
$data = fgets($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ $result = true; }
}
}
}
fclose ($connection);
if ($result) { return true; }
}
}
$id++;
} 
return false;
}
}
?>
// esempio
function checkmail($address) 
{
$smtp = new CSmtp();
if ($smtp->checkmail($address))
{ return "Ok"; }
else
{ return "Ko"; }
}
poi, dato che su windows non funziona, ha suggerito di aggiungere 
<?php
function win_getmxrr  ($hostname = "", &$mxhosts, $weight = array())
{
$command = "nslookup -typ
e=mx " . $hostname;
$nslookup = array ();
$mx = array ();
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 );
$mxhosts = $mx;
return count($mxhosts)>0;
}
$mx = array();
win_getmxrr("
google.com
", $mx);
print_r ($mx);
?>
io ho mescolato il tutto ottenendo
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
function getmxrr  ($hostname = "", &$mxhosts, $weight = array())
{
$command = "nslookup -type=mx " . $hostname;
$nslookup = array ();
$mx = array ();
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 );
$mxhosts = $mx;
return count($mxhosts)>0;
}
$mx = array();
getmxrr("
google.com
", $mx);
print_r ($mx);
define ('DEBUG_OK', false);
Class CSmtp
{
var $timeout = 10;
function checkmail ($email = "")
{
$host = substr (strstr ($email, '@'), 1, 255) . ".";
if (getmxrr ($host, $mxhosts[0],  $mxhosts[1]) == true)
{ array_multisort ($mxhosts[1],  $mxhosts[0]); }
else
{
$mxhosts[0] = $host;
$mxhosts[1] = 10;
}
if (DEBUG_OK) { print_r ($mxhosts); }
$port = 25;
$error = '';
$localhost = '
alientech.it
';
$sender = 'info@' . $localhost;
$result = false;
$id = 0;
while (!$result && $id < count($mxhosts[0]))
{
if (function_exists ("fsockopen"))
{
if (DEBUG_OK) { print_r ($id . " " . $mxhosts[0][$id]); }
if ($connection = fsockopen ($mxhosts[0][$id], $port, $errno, $error,
$this->timeout))
{
fputs ($connection,"HELO $localhost\r\n"); // 250
$data = fgets ($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ 
fputs ($connection,"MAIL FROM:<$sender>\r\n");
$data = fgets($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ 
fputs ($connection,"RCPT TO:<$email>\r\n");
$data = fgets($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ 
fputs ($connection,"data\r\n");
$data = fgets($connection,1024);
$response = substr ($data,0,1);
if (DEBUG_OK) { print_r ($data); }
if ($response == '2') // 200, 250 etc.
{ $result = true; }
}
}
}
fclose ($connection);
if ($result) { return true; }
}
}
$id++;
} 
return false;
}
}
// esempio
function checkmail($address) 
{
$smtp = new CSmtp();
if ($smtp->checkmail($address))
{ return "Ok"; }
else
{ return "Ko"; }
}
checkmail ("
mup...@libero.it
");
?>
</body>
</html>
però mi da questi errori
Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in c:\programmi\apache group\apache\htdocs\mail.htm on line 49
Warning: fsockopen() expects parameter 1 to be string, array given in c:\programmi\apache group\apache\htdocs\mail.htm on line 69
Warning: fsockopen() expects parameter 1 to be string, array given in c:\programmi\apache group\apache\htdocs\mail.htm on line 69
Warning: fsockopen() expects parameter 1 to be string, array given in c:\programmi\apache group\apache\htdocs\mail.htm on line 69
Warning: fsockopen() expects parameter 1 to be string, array given in c:\programmi\apache group\apache\htdocs\mail.htm on line 69
Warning: fsockopen() expects parameter 1 t
o be string, array given in c:\programmi\apache group\apache\htdocs\mail.htm
on line 69
dove la linea 49 è
{ array_multisort ($mxhosts[1],  $mxhosts[0]); }
e la 69 è
if ($connection = fsockopen ($mxhosts[0][$id], $port, $errno, $error,
$this->timeout))
Qualche suggerimento, in particolare dal buon Setec ;)) ??
Grazie
Andrea

 Qualche suggerimento, in particolare dal buon Setec ;)) ??
Si:
1^ non fare un post come questo. 
2^ Prima di continuare a fare tentativi penosi di copia ed incolla,
comprati un buon libro e studiatelo.
All'indirizzo 
http://digilander.iol.it/setecastronomy/smtp_win.php
 e
disponibile una versione che funziona sotto windows, non e' posrtbaile
direttamente sotto linux, ma non ho tempo ne voglia di renderla tale.
-- 
I'am what I'am, I do what I can
Sei un newbie? Leggi questo 
http://tinyurl.com/26nej
 

 direttamente sotto linux, ma non ho tempo ne voglia di renderla tale.
Grazie!
Andrea