Sunday, October 6, 2013

Block temporary emails using PHP

It's really sucks when someone registers on site using temporary email address. This is not good for business. Especially if you pay online services to handle your email marketing campaign. That's why you need securing your registration form not just for email validation, but also prevent receiving contacts that you will never be able to follow up them. I did this by filtering inputs and detect email domain to make sure it isn't in temporary email service list.

Here's how:
First, download temporary-email-services.txt. The file contains domain of temporary email service.
0-mail.com
0815.ru
0clickemail.com
0wnd.net
0wnd.org
10minutemail.com
20minutemail.com
2prong.com
...

Then on PHP file:

<?php
$file = str_replace("\r\n",',',file_get_contents('temporary-email-services.txt'));
$blacklisted = explode(',',$file);

$email = strtolower( $_POST['email'] );

// get the domain of email address
$r = explode('@',$email);
$email_domain = $r[1];

if( in_array( $r[1] , $blacklisted ) ) {
   echo "It seems like a temporary email. Please use other email service.";
}
else {
   // Save email
}
?>

No comments :

Post a Comment