Jump to content

Block email extension's


sphinx

Recommended Posts

Hello,

 

I'm currently using this to block certain emails:

 

$blacklisted = Array("email@email.com", "email2@email.com", "email3@email.com");

 

in with:

 

if( !in_array( strtolower($email), $blacklisted ) ) {

 

Ok, What I want to do, is be able to specify a domain extension such as '*@email.com' So anything with 'something'@email.com is blocked. I still wish to keep manual email address's in place aswell.

 

Many thanks

 

James

Link to comment
Share on other sites

This worked for me:

 

<?php
$blacklistArr = array("email@email.com", "email2@email.com", "email3@email.com", "@gmail.com");
function isBL($e){
global $blacklistArr;
$isBlackListed = false;
foreach($blacklistArr as $email){
	$email = preg_quote($email);
	if(preg_match("/$email/i", $e)){
		$isBlackListed = true;
		break;
	}
}
return $isBlackListed;
}

$tests = array("email@email.com", "myemail@gmail.com", "email23@email.com", "email2@email.com", "mike@yahoo.com");
foreach($tests as $email){
echo "$email: ";
var_dump(isBL($email));
echo "<br>";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.