Jump to content

[SOLVED] validation errors


NickG21

Recommended Posts

hey everyone, this is my code to validate an e-mail address.  the email is accepted but these are the errors i receive, any idea where my problems are or how to fix them? thank you

Warning: fsockopen(): php_network_getaddresses: getaddrinfo failed: Name or service not known in .../emailcheck.php on line 15

Warning: fsockopen(): unable to connect to :25 in .../emailcheck.php on line 15
[code]
<?php
function checkEmail($email)
{
  if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $email))
  {
      return FALSE;
  }
  list($Username, $Domain) = split("@",$email);
  if(getmxrr($Domain, $MXHost))
  {
      return TRUE;
  }
  else
  {
      if(fsockopen($Domain, 25, $errno, $errstr, 30))
      {
        return TRUE;
      }
      else
      {
        return FALSE;
      }
  }
}
if (isset($_POST['submit'])) {
$email = $_POST['email'];
if(checkEmail('$email') == FALSE)
{
  echo "E-mail entered is not valid.";
}
else
{
  echo "E-mail entered is valid.";
}
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<form method="post" action="emailcheck.php">
<table class="qForm">
<tr>
<td><a>Email:</a></td>
<td><input type="text" size="28" name="email" value-<? echo"$email"?>"><br/></td>
</tr>
<tr>
<input type="hidden" value="1"
<td><input type="submit" name="submit" value="submit"></td>
</tr>
</table>
</form>
</body>
</html>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/31993-solved-validation-errors/
Share on other sites

You might want to error supress this line. eg;

[code=php:0]
if(@fsockopen($Domain, 25, $errno, $errstr, 30))
[/code]

Also note that variables do not need to be surrounded by quotes and in particular, surrounding them with single quotes meens they will not be parsed. So this line becomes....

[code=php:0]
if(checkEmail($email) == FALSE)
[/code]

And even better....

[code=php:0]
if (checkEmail($email))
[/code]

Does the same thing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.