bubblybabs Posted April 24, 2007 Share Posted April 24, 2007 I wish to exclude a specific email address when one sends an ecard from my site. How does one exlude this email address but allow all others to continue on their merry way? Code currently used: function validEmail($address) { if (eregi("^[a-z0-9]([\._\-]?[a-z0-9])*@[a-z0-9]([\.\-]?[a-z0-9])*\.[a-z]{2,}$", $address)) return true; else return false; } Thank-you, Babs Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 if(validEmail($_POST[email])){ if(strpos($_POST[email],'bad@email.host')!==false){ FLEEFROMMYWRATH($baduser); }else{ } } Quote Link to comment Share on other sites More sharing options...
bubblybabs Posted April 24, 2007 Author Share Posted April 24, 2007 taith, I so appreciate your quick response... Please give me a clue as to how to add this snippet of coding into what I already have... Should it be as such? function validEmail($address) { if (eregi("^[a-z0-9]([\._\-]?[a-z0-9])*@[a-z0-9]([\.\-]?[a-z0-9])*\.[a-z]{2,}$", $address)) return true; else return false; } if(validEmail($_POST[email])){ if(strpos($_POST[email],'bad@email.host')!==false){ FLEEFROMMYWRATH($baduser); }else{ } } Babs Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 sorry... not really sure what you mean by that... this should work as is... but it really depends on how your script works... function validEmail($address){ if(eregi("^[a-z0-9]([\._\-]?[a-z0-9])*@[a-z0-9]([\.\-]?[a-z0-9])*\.[a-z]{2,}$", $address)) return true; else return false; } if(validEmail($_POST[email])){ if(strpos($_POST[email],'bad@email.host')!==false){ die('I dont like that user... go away!'); }else{ #continue your script } } Quote Link to comment Share on other sites More sharing options...
bubblybabs Posted April 24, 2007 Author Share Posted April 24, 2007 My dear, this is looking good... I had to modify this a bit to work in the script I am using but it worked... One exception, how does one make it so that it's not case sensitive? Right now, if I were to put this email address into the code: happy@happy.com but the person typed in : Happy@happy.com it will go through. An error is produced if the two are typed in exactly the same however... Also, is there a way to block all emails from a specific domain? For example, all emails to @happy.com? Thanks, Babs Quote Link to comment Share on other sites More sharing options...
bubblybabs Posted April 24, 2007 Author Share Posted April 24, 2007 I think I found the answer... I changed strpos to stristr... Is this correctly used? function validEmail($address) { if(eregi("^[a-z0-9]([\._\-]?[a-z0-9])*@[a-z0-9]([\.\-]?[a-z0-9])*\.[a-z]{2,}$", $address)) return true; else return false; } if(validEmail($_POST[to_email])){ if(stristr($_POST[to_email],'happy@happy.com')!==false){ die('I am sorry but you are not allowed to send to that email address. Please go <a href="compose.php">back</a> and fix the error.'); }else{ return false; } } I can put in happy@happy.com and change any letter to a capital and it seems to give me the error message so I think this is correct... Thanks, Babs Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 yes... it would work that way... :-) strpos() is faster... just if you go that way, just strtolower() the $_POST'd email first... Quote Link to comment Share on other sites More sharing options...
bubblybabs Posted April 24, 2007 Author Share Posted April 24, 2007 OK, took me a bit to figure this out: function validEmail($address) { if(eregi("^[a-z0-9]([\._\-]?[a-z0-9])*@[a-z0-9]([\.\-]?[a-z0-9])*\.[a-z]{2,}$", $address)) return true; else return false; } if(validEmail($_POST[to_email])) { if(strpos(strtolower($_POST[to_email]),'happy@happy.com')!==false) { die('So sorry but you are not allowed to send to that email address. Please go <a href="compose.php">back</a> and resend to another email address. Thank-you!.'); }else{ return false; } } Is that correctly coded? Thanks bunches... Babs Quote Link to comment Share on other sites More sharing options...
taith Posted April 24, 2007 Share Posted April 24, 2007 does it work? Quote Link to comment Share on other sites More sharing options...
bubblybabs Posted April 25, 2007 Author Share Posted April 25, 2007 *giggles* Yes, it works! I just worry I've gotten it to work but some hidden other "side-code" is occurring w/o my knowledge! :-) Many thanks taith, I appreciate your assistance and helping me learn yet another fascinating snippet of php... Consider this solved! Babs Quote Link to comment 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.