Jump to content

Block email extension's


sphinx

Recommended Posts

Hello,

 

I'm currently using this to block certain emails:

 

$blacklisted = Array("[email protected]", "[email protected]", "[email protected]");

 

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
https://forums.phpfreaks.com/topic/251990-block-email-extensions/
Share on other sites

This worked for me:

 

<?php
$blacklistArr = array("[email protected]", "[email protected]", "[email protected]", "@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 protected]", "[email protected]", "[email protected]", "[email protected]", "[email protected]");
foreach($tests as $email){
echo "$email: ";
var_dump(isBL($email));
echo "<br>";
}
?>

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.