Jump to content

Server Side Validation e-mail


NickG21

Recommended Posts

hey everyone, i was wondering if anyone could take a quick look at the code i have below.  i am trying to create a form that has e-mail validation on it, i have all the syntax validation down but i am unable to figure out the server side.  this is what i have come up with from the tutorials and other scripts i have been reading.  thanks to everyone in advance

[code]<?php
function checkEmail($email)
{
  if (!preg_match("/^([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'];
  $name = $_POST['text1'];
  $number = $_POST['text2'];
  $error = array();

  // check e-mail address
  // display success or failure message
  if (!preg_match("/^([a-zA-Z])+/",$name)){
  $error[] = "Your Name May Only Contain Letters";
  $name="";
}
  if (!preg_match("/^([0-9])+/",$number)){
  $error[] = "Invalid ZipCode";
  $number="";
}
if (CheckEmail($email) == FALSE)
{
  $error[] = "Invalid E-Mail Address";
  $email="";
  }

  if (count($error)>0) {
    $msg = "<p class=\"error\"><big><b>The Following Errors Were Found, Please Re-Enter:</b></big><br/>". implode('<br />', $error). "</p>";
    } else {
    $msg = "<p><b>Thank You, Your Information Has Been Accepted</b></p>";
  }
}

echo isset($msg) ? $msg : '';
?>
<!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 action="emailserver.php" method="post">
<table class="qForm">
<tr>
<td class="left"><a>Your Name:</a></td>
<td><input type="text" size="28" name="text1" value="<? echo"$name"?>"><br/></td>
</tr>
<tr>
<td class="left" ><a>Zip Code:</a></td>
<td><input type="text" size="28" name="text2" maxlength="5" value="<? echo"$number"?>"><br/></td>
</tr>
<tr>
<td class="left"><a>E-Mail Address:</a></td>
<td><input type="text" name="email" size="28" value="<? echo"$email"?>"><br/></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"><br/></td>
<td class="left"><input type="reset" name="reset" value="Reset"></td>
</tr>
</table>
</form>
</body>
</html>[/code]
Link to comment
https://forums.phpfreaks.com/topic/31963-server-side-validation-e-mail/
Share on other sites

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.