Socket/Check Mail problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Socket/Check Mail problem

Post by bla5e »

The Function:

Code: Select all

<?php
function checkEmail($email) 
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $e)) 
   {
      return FALSE;
   }

   list($Username, $Domain) = split("@",$e);

   if(getmxrr($Domain, $MXHost)) 
   {
      return TRUE;
   }
   else 
   {
      if(fsockopen($Domain, 25, $errno, $errstr, 30)) 
      {
         return TRUE; 
      }
      else 
      {
         return FALSE; 
      }
   }
}
?>

The Code:

Code: Select all

<?php
if(checkEmail($email) == FALSE) {
   			echo "E-mail entered is not valid.";
		} else {
   			echo "E-mail entered is valid.";
		}
?>
$email = from a previous page/form



The Error:
Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /home/steve/public_html/teamexileonline/index.php on line 17

Warning: fsockopen(): unable to connect to :25 in /home/steve/public_html/teamexileonline/index.php on line 17
Line 17 = <?php if(fsockopen($Domain, 25, $errno, $errstr, 30)) ?>
User avatar
hopfateam
Forum Newbie
Posts: 12
Joined: Sun May 29, 2005 6:30 pm
Location: Germany
Contact:

Re: Socket/Check Mail problem

Post by hopfateam »

bla5e wrote:The Function:

Code: Select all

<?php
function checkEmail([b]$email[/b]) 
{
   if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", [b]$e[/b])) 
   {



[/quote]

Mistake should be using $e instead of function´s variable $email, which let´s u receive a wrong parameter $Domain which is then used in line 17
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

One small thing, and it's probably just me, but you could be a little more courteous than just posting some code and an error and expecting people to fix it for you. A "please can you help?" would be nice.

As it happens your email matching regex is wrong. Even if you correct the error in the regex itself it still wouldn't match my email address. Check the regex folder on here to find a better one.
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Post by bla5e »

onion2k wrote:One small thing, and it's probably just me, but you could be a little more courteous than just posting some code and an error and expecting people to fix it for you. A "please can you help?" would be nice.

As it happens your email matching regex is wrong. Even if you correct the error in the regex itself it still wouldn't match my email address. Check the regex folder on here to find a better one.
where can i find the regex folder on here, please :-)
Roja
Tutorials Group
Posts: 2692
Joined: Sun Jan 04, 2004 10:30 pm

Post by Roja »

bla5e wrote: where can i find the regex folder on here, please :-)
viewforum.php?f=38

And for the definitive RFC-compliant regex, you can grab a GPL-licensed validateemail function:

http://svn.gna.org/viewcvs/blacknova/tr ... iew=markup
Post Reply