| | 348 | * Test email onto MX host |
|---|
| | 349 | * |
|---|
| | 350 | * This function performs a test to MX host, and check if e-mail is valid or not |
|---|
| | 351 | * |
|---|
| | 352 | * @param string $srv Server to test |
|---|
| | 353 | * @param string $email The email to validate |
|---|
| | 354 | * |
|---|
| | 355 | * @return bool Returns if email exists or not |
|---|
| | 356 | * |
|---|
| | 357 | * @static |
|---|
| | 358 | * @access public |
|---|
| | 359 | */ |
|---|
| | 360 | |
|---|
| | 361 | public function testMail($srv, $email) |
|---|
| | 362 | { |
|---|
| | 363 | |
|---|
| | 364 | $host = $_SERVER['SERVER_NAME']; |
|---|
| | 365 | $from = "rafi@wireless-fr.org"; |
|---|
| | 366 | $fromLine = "mail from: check@$host\n"; |
|---|
| | 367 | $rcpt = "rcpt to: $email\n"; |
|---|
| | 368 | |
|---|
| | 369 | /* Create a new Net_SMTP object. */ |
|---|
| | 370 | if (! ($smtp = new Net_SMTP($srv))) { |
|---|
| | 371 | // echo("Unable to instantiate Net_SMTP object\n"); |
|---|
| | 372 | return false; |
|---|
| | 373 | } |
|---|
| | 374 | |
|---|
| | 375 | /* Connect to the SMTP server. */ |
|---|
| | 376 | if (PEAR::isError($e = $smtp->connect())) { |
|---|
| | 377 | // echo($e->getMessage() . "\n"); |
|---|
| | 378 | return false; |
|---|
| | 379 | } |
|---|
| | 380 | |
|---|
| | 381 | /* HELO to the SMTP server. */ |
|---|
| | 382 | if (PEAR::isError($e = $smtp->helo($host))) { |
|---|
| | 383 | // echo($e->getMessage() . "\n"); |
|---|
| | 384 | return false; |
|---|
| | 385 | } |
|---|
| | 386 | |
|---|
| | 387 | /* Send the 'MAIL FROM:' SMTP command. */ |
|---|
| | 388 | if (PEAR::isError($smtp->mailFrom($from))) { |
|---|
| | 389 | // echo("Unable to set sender to <$from>\n"); |
|---|
| | 390 | return false; |
|---|
| | 391 | } |
|---|
| | 392 | |
|---|
| | 393 | /* Address the message to each of the recipients. */ |
|---|
| | 394 | if (PEAR::isError($res = $smtp->rcptTo($email))) { |
|---|
| | 395 | // echo("Unable to add recipient <$email>: " . $res->getMessage() . "\n<br />Error ".implode(": ",$smtp->getResponse())); |
|---|
| | 396 | return false; |
|---|
| | 397 | } |
|---|
| | 398 | |
|---|
| | 399 | /* Disconnect from the SMTP server. */ |
|---|
| | 400 | $smtp->disconnect(); |
|---|
| | 401 | return true; |
|---|
| | 402 | } |
|---|
| | 403 | |
|---|
| | 404 | |
|---|
| | 405 | /** |
|---|
| | 434 | |
|---|
| | 435 | // Check if email is valid on mx host |
|---|
| | 436 | |
|---|
| | 437 | // gets domain name |
|---|
| | 438 | list($username,$domain)=split('@',$email); |
|---|
| | 439 | // checks for if MX records in the DNS |
|---|
| | 440 | $mxhosts = array(); |
|---|
| | 441 | if(!getmxrr($domain, $mxhosts)) { |
|---|
| | 442 | // no mx records, ok to check domain |
|---|
| | 443 | $fp=@fsockopen($domain,25,$errno,$errstr,30); |
|---|
| | 444 | if (!$fp) { |
|---|
| | 445 | $_retVal = false; |
|---|
| | 446 | } else { |
|---|
| | 447 | fclose($fp); |
|---|
| | 448 | $_retVal = testMail($host,$email); |
|---|
| | 449 | } |
|---|
| | 450 | } else { |
|---|
| | 451 | // mx records found |
|---|
| | 452 | foreach ($mxhosts as $host) { |
|---|
| | 453 | // echo "MX host : ".$host."<br>\n"; |
|---|
| | 454 | $fp=@fsockopen($host,25,$errno,$errstr,30); |
|---|
| | 455 | if ($fp) { |
|---|
| | 456 | fclose($fp); |
|---|
| | 457 | $_retVal = Mail::testMail($host,$email); |
|---|
| | 458 | } |
|---|
| | 459 | } |
|---|
| | 460 | } |
|---|