Jump to content

e-mail server validation


NickG21

Recommended Posts

hey everyone.  below is my code for a basic validation script with a CheckEmail function that is supposed to try and access the domain server used in order to assure that the e-mail address being used is a valid e-mail.  the context seemed alright to me, but i am unsure of the variables and if they need to be declared in other areas to specifiy the information being sent. here are the codes and the errors
any help/tutorials are greatly appreciated
thank you

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

Warning: fsockopen(): unable to connect to nick.edu:25 in .../emailserver.php on line 15

Code:
[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 : '';
?>[/code]
Link to comment
https://forums.phpfreaks.com/topic/31526-e-mail-server-validation/
Share on other sites

Check out the users contribution notes in the manual for some examples:
http://no.php.net/manual/en/function.getmxrr.php

You could however add error surpressing on the fsockopen to prevent errors during check, if the domain is unavailable (false) the error msg will print out on this part.
[code]
@fsockopen($Domain, 25, $errno, $errstr, 30)
[/code]

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.