FRIHOSTFORUMSSEARCHFAQTOSBLOGSCOMPETITIONS
You are invited to Log in or Register a free Frihost Account!


PHP email varification saying invalid email





spider
I used this tutorial here:

Email Address Verification with PHP

here is the code I have used:
Code:

<?
function CheckDnsrr($host,$recType='') {
 if(!empty($host)) {
  if($recType=='') $recType="MX";
  exec("nslookup -type=$recType $host",$output);
  foreach($output as $line) {
   if(preg_match("/^$host/", $line)) {
    return true;
   }
  }
  return false;
 }
 return false;
}

function checkEmail($email) {
 // checks proper syntax
 if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)) {
  // gets domain name
  list($username,$domain)=split('@',$email);
  // checks for if MX records in the DNS
  if(!checkdnsrr($domain, 'MX')) {
   return false;
  }
  // attempts a socket connection to mail server
  if(!fsockopen($domain,25,$errno,$errstr,30)) {
   return false;
  }
  return true;
 }
 return false;
}

if(!$_POST['email']) {
     die('Error: Email field was blank.');
}else{
       $email = trim($_POST['email']);   
         if(!checkEmail($email)) { 
         echo 'Invalid email address!';
         }
         else {
         $email1 = $_POST['email'];
         }
}

?>


and when I use my admin email:
admin@tusc-oh.com
or my personal email:
tim-n-mary@peoplepc.com

it returns Invalid email address!

any suggestions or help would be appreciated.
badai
most probably something wrong with the regex.

you can just replace it with better regex. try google it.

i'm not good with interpreting regex, but does it check "dash" as invalid character?
hexkid
spider wrote:
preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9\._-] )*@( [a-zA-Z0-9_-] )+( [a-zA-Z0-9\._-] +)+$/" , $email)


Let's see:
Code:
^                                    start of subject
(...)                                group
    <space>[a-zA-Z0-9]<space>          three characters
+                                    repeat one or more of the group
(...)                                group
    <space>[a-zA-Z0-9\._-]<space>      three characters
*                                    repeat zero or more of the group
@                                    literal @
(...)                                group
    <space>[a-zA-Z0-9_-]<space>        three characters
+                                    repeat one or more of the group
(...)                                group
    <space>                            space
    [a-zA-Z0-9\._-]                    character
    <space>+                           one or more spaces
+                                    repeat one or more of the group
$                                    end of the subject


So, excluding the quotes, here is one string that matches that regular expression:
Code:
" f  o  o @ b  a                      r  .  c  o  m "



If you're on Windows try The Regex Coach.
badai
so now we know. i am impressed!!!!
spider
Sorry so long guys... thanks,, Ive always had problems with those... Its been so long cant even remember what to call them... lol
looks like I'll have to study up all over again...lol
Thanks again..
Related topics
php mailing script
Simple and Detailed Mail Script
php dropdown lists with if statements or switch
Forms...
Help with Dreamweaver sessions !!!!!!!!
Emailing Username And Password
Page Based Email Issue
Textbox Submit to email
Email in saying do not delete?
*solved*
Help with php email
selecçao de emails no php . email selection on php
Server Configuration Problem
htaccess pattern for an email
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.