Mr P!nk Posted August 10, 2007 Share Posted August 10, 2007 Can someone tell me how this checks the domain? does it scan the net or just check to see if the address is a valid one? ??? This code was found http://www.phpfreaks.com/quickcode/Function-to-check-for-valid-email-and-domain/451.php?higlight=email+ I'm asking this because i need to make sure no spammers add themselves to our email newsletter. function checkEmail($email) { 1 if(preg_match("/^( [a-zA-Z0-9] )+( [a-zA-Z0-9._-] )*@( [a-zA-Z0-9_-] )+( .[a-zA-Z0-9_-] +)+$/" , $email)){ 2 list($username,$domain)=split('@',$email); 3 4 if(!customCheckDnsrr($domain)){ 5 return false; } 6 7 return true; 8 } 9 10 return false; 11 } 12 13 function customCheckDnsrr($host,$recType='') { 14 if(!empty($host)) { 15 16 if($recType=='') $recType="MX"; 17 exec("nslookup -type=$recType $host",$output); 18 foreach($output as $line) { 19 20 if(preg_match("/^$host/", $line)) { 21 return true;} 22 23 } 24 25 return false; 26 } 27 28 return false; 29 } 30 31 32 /////// The php to check form 33 34 // Check for email and verify 35 // If empty input echo error 36 if (empty ($_POST['email'])) { 37 $email = FALSE; 38 echo 'Please enter a email address!<br />'; 39 } else { 40 // Check to make sure its a valid email, and already exists 41 if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+.[a-z]{2,4}$", 42 stripslashes(trim($_POST['email'])))) { 43 $email = $_POST['email']; 44 $check_email = "SELECT email FROM table WHERE email='$email'"; 45 $result = mysql_query($check_email) or die (mysql_error()); 46 // If username exists echo taken error 47 if (mysql_num_rows($result) > 0) { 48 $email = FALSE; 49 echo 'That email is already being used!<br />'; 50 } else { 51 // Check to see if emails match 52 if ($_POST['email'] == $_POST['email_verify']) { 53 $email = trim($_POST['email']); 54 if (!checkEmail($email)) { 55 echo 'Invalid email address!<br />'; 56 } else { 57 $email = TRUE; 58 $email = $_POST['email']; 59 } 60 } else { 61 $email = FALSE; 62 echo 'Your email address did not match!<br />';} } 63 } else { 64 // If email is not valid echo error 65 $email = FALSE; 66 echo 'That is not a valid email address!<br />';} 67 } 68 69 /// This all uses boolean true and fasle... to just continue do 70 71 if ($email = TRUE) { 72 echo 'Thank You'; 73 } else { 74 echo 'Please try again!<br />';} 75 Thanks in advance Ladies and gentlemen Quote Link to comment https://forums.phpfreaks.com/topic/64253-need-a-bit-of-explanation-please/ Share on other sites More sharing options...
MadTechie Posted August 10, 2007 Share Posted August 10, 2007 it check if the domain is a valid name for a domain, it doesn't check to see if it exists for example www.phpfreaks.com will work but phpfreaks.chimps will fail but www.wearenotfreaks.com will works (just it doesn't exist) i think thats what you were asking Quote Link to comment https://forums.phpfreaks.com/topic/64253-need-a-bit-of-explanation-please/#findComment-320309 Share on other sites More sharing options...
Mr P!nk Posted August 10, 2007 Author Share Posted August 10, 2007 yea that's what i was getting at. is there anything i can use/implement into my coding that stops spammers adding themselves to our database? i get email notifications every time someone registers of course but I don't have the time to cross check them all. thanks Quote Link to comment https://forums.phpfreaks.com/topic/64253-need-a-bit-of-explanation-please/#findComment-320315 Share on other sites More sharing options...
MadTechie Posted August 10, 2007 Share Posted August 10, 2007 how do you know if their a spammer ? thats the first question as soon as you know that you can code for it.. Quote Link to comment https://forums.phpfreaks.com/topic/64253-need-a-bit-of-explanation-please/#findComment-320325 Share on other sites More sharing options...
Mr P!nk Posted August 10, 2007 Author Share Posted August 10, 2007 Hmmm true. i guess i could always use a validation process to which the registrar has to wait for me to activate them to which i then know if im going to be spammed. any ideas for what to look for in spammers addresses? e.g an invalid domain/url. but even then i get spam from people using email addresses of clients with valid domains. !!! Damn all you spammers why do you make our lives so difficult ?!?!?! Thanks anyway MadTechie you have been rather helpful Quote Link to comment https://forums.phpfreaks.com/topic/64253-need-a-bit-of-explanation-please/#findComment-320347 Share on other sites More sharing options...
wildteen88 Posted August 10, 2007 Share Posted August 10, 2007 You could use one of the gethostby* functions to verify the domain name. However using gethostby* can be be slow. Quote Link to comment https://forums.phpfreaks.com/topic/64253-need-a-bit-of-explanation-please/#findComment-320350 Share on other sites More sharing options...
Mr P!nk Posted August 10, 2007 Author Share Posted August 10, 2007 You could use one of the gethostby* functions to verify the domain name. However using gethostby* can be be slow. Yea that was my initial thought, and yes your right (well you are a genius) it was way to slow, i imagine people would think there was a problem after entering there address and close their browser therefore annoying them. Thanks for your input though appreciated Quote Link to comment https://forums.phpfreaks.com/topic/64253-need-a-bit-of-explanation-please/#findComment-320357 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.