When you have obtained a list of emails from a location that required little to no validation on whether it was a real email, you will be stuck trying to determine if the email address is real or not. You don’t want to risk sending out an email to these users without checking as a regular high bounce rate is a quick way to get your email server blacklisted. There is a 2 step method that you can use to validate if an email address is valid or not. This assumes that you have first filtered out values that are missing an @ symbol and a domain. This guide will show you how to check if an email is valid. For example, how can you tell if is real or fake?

Step 1

The first thing you will need to do is check if the domain name is valid and has an active mail server/ MX record associated with it. Sometimes an email may have been valid at one stage, but the website has now been shut down. Sending an email to this address wont do anything. By checking to see if the domain name is real you will be able to filter out people who provide stupid domain names that never existed and also filter out emails from valid websites that are not capable of receiving emails.

For the example I am going to use PHP to write the script for this. Many other languages have similar methods that do the same thing, so this should be fairly easy to do with other programming languages. PHP has a function called “getmxrr()”. This function will obtain the MX record for a domain. For those who do not know what this is, a MX record is used in the DNS settings to point to the IP of a domains email server. If one is missing then the domain is not capable of receiving an email and is therefore invalid.

Just because a domain has an MX record, does not mean that the email address is valid. In fact, this makes sending bad emails to this server even more likely to cause you to get blacklisted.

Step 2

This is the most difficult to test while also being the most important. If someone provides an email like, step 1 will return this as being a valid email address. is a valid email domain, but asdasd is likely a non existent user. This step will allow you to determine whether this is a valid inbox or not. Keep in mind that this step requires you to directly contact the email server to essentially ask if the inbox exists. I would suggest you run this from a test machine so you do not run the risk of blacklisting the IP. This many requests in a short period might be considered suspicious.

If you have worked with mail servers in the past, you may be familiar with HELO. This can be used to easily check if a mailbox exists or not. If you send the command and get a positive response you know that this inbox exists. If not you know its fake. I have combined step 1 with step 2 to generate a complete script below that will allow you to check if an email is valid and filter out bad mailboxes.


command line

Installing can be quite simple to do and also very dangerous as you install something, it completely wrecks apache and now your web server wont start back up again. Well worry not, its very easy to uninstall anything that you have installed. The first thing you need to know is that the name of the package changes from the name of the original file that you downloaded and installed. You will first need to perform a search of everything that is installed to get the name of the package you are looking for. Using grep will make this way easier.

This will generate a massive list of all of the packages installed on your system if you run it without the grep. Once you have found the name of the package you want to install run the following command to uninstall an RPM package from your system.

If the RPM that you installed was part of another application such as an apache module, make sure to run the command to restart the application in case it has crashed with the install of the RPM.

Thankfully this is very easy to perform. You can begin to get over the mini heart attack you had when your server went down now 🙂

When running a web server it’s vital that you have you important that you have applications like apache and mysql start when the system does. Who knows what might trigger a reboot and even more, you don’t want to perform a quick restart and have the entire server crumble. Well fear not, it is very easy to set up your system for running applications on system startup.

The following command will work for Centos and Red Hat Linux.

Run the above command in your command line tool and mysql will be set to start when the system does. Replace mysql with another application name such as httpd to make that application start up on boot too.

Most standard PDO tutorials from around the web are going to demonstrate using a MySQL database with apache as a web host. The PDO connection string for this setup is not going to work if you want to connect to a SQL Server database using Microsofts IIS server.

The first step is to make sure PHP is setup to connect to SQL Server. PHP is going to use the sqlsrv driver on IIS in order to connect to SQL Server. This will probably be installed already, but to make sure you will have to go to your php.ini file. If you are unsure where this file is located you can use phpInfo() to find out the file path of the php.ini file.

You need to open the file and check for the following line. If its commented out, uncomment it. If its missing then add it. If it’s not present then there is a chance that the driver is not installed at all, if so then you will need to install it.

If you don’t have the driver installed, you can get it here.

Once you are all setup with the driver and php is good to go, restart IIS to make sure that the changes with the php.ini are picked up by IIS.


When making a query the code stays the same, but the PDO connection string is going to be different. Use the following format and add the connection details for your server into the string.

This should be all you need to connect to an SQL Server database using PHP with IIS web host.

Reverse DNS is a common method used to help keep your emails out of the dreaded spam filters. Fortunately, once you know how, reverse DNS is a quick and easy way to improve the trustability of your emails. Reverse DNS alone is not enough to guarantee that your emails will successfully make it to a users inbox, but its a quick and easy way to start. I suggest you look at DKIM keys after you have this completed as these will also greatly help you out. Click here for a guide on setting up DKIM keys for emails.

So first things first. Where do you go to set this up?

Most people think that it’s the job of your domain registrar (i.e. GoDaddy) to do this, but this is not the case. Your hosting provider is responsible for this. If you are using a shared host, you may not have access to do something like this. Generally to have a reverse DNS your website will need to have its own dedicated IP address and not be shared as a virtual host on a server somewhere. If you are unsure about this get in touch with the company that host your website and they will help you out further.

If you have your own server, be it VPS, dedicated or some other system, you should be able to set this up very easily. When you register for an account you will be given an IP for your server. This is the IP that you enter for your domain name in Godaddy or whatever domain registrar you use.  This means that will map to the IP address of your server. Reverse DNS is making sure that that same IP address reverse maps back to your domain name.

Start by logging into whatever managment system your host has provided for you. If you don’t have one then get in touch with the host and they will tell you where to find the form. Generally there will be a simple form and you can just type the name of the domain into a box and after a few minutes, the IP of your server will map back to your name. It’s a very simple yet effective thing to do to combat the spam filter war!

DomainKeys Identified Mail (DKIM) is a process used to validate emails preventing someone from sending spam email using an unauthorised email address. The process works using 2 encrypted SSL keys. A public key which is obviously made available to the public and a private key which only you / your web server will know. When you send an email you will attach your private key to the email. When gmail or any other web server gets the email, it will check to see if the public key that you have made available via your DNS zone file, matches up with the private key that was sent with the email. DKIM is a one useful method to prevent your emails ending up in spam folders.

Setting up DKIM for your web server may seem like it is incredibly complicated and there is no sucks! but as long as you have some experience working with a web server and have access to everything needed, you should be able to get this setup. To make life as easy as possible I will break this down into a series of individual steps.

Step 1 – Generate a private and public key
Creating your public and private keys are less complicated than you might think. SSL keys can be generated by any machine, you don’t have to register for an account anywhere or setup anything special. You simply download an application and it will generate the keys for you. It’s best to do this on your own machine rather than use an online service as you don’t know if the online service could be saving these keys.

So to create the keys you will need to download a command line SSL tool. You can find a download link here . Download and install this tool. In order to run it you will need to open up a command shell window (command prompt) in administrator mode if you are running windows vista or newer.

When in a command window run the following commands. You might need to give the direct path of the .exe file in order for the command to work. This will generate 2 files (rsa.private and rsa.public) in whatever folder you are currently in. It will be best to change directory to the desktop or the root of the C drive in order to get at these files quickly.

You now have a public and private key!

Step 2 – Add DNS records
The DNS record is where you are going to store the public key. When gmail gets an email from your server it will check the dns record for the domain and see if there is a key available. If there is one there is will have the public key which it can use with the private key that was send with the email.

This part of the guide will depend on where your DNS zone file is hosted. For most people godaddy will likely be the place where the zone file is hosted. If you don’t use godaddy then you will have to find out how to edit your zone file. This is a very important file, so if you dont know how to edit it you will have bigger issues than setting up domain keys.

You need to add 2 TXT records to your zone file. I wanted to create a record for a noreply email address so that my server could send out emails to users automatically and the emails would make it to the inbox folder and not the spam folder.

Add the following data to the Host and TXT fields of your zone file.


NOTE!! Make sure the public key is one long string with out any whitespace or line breaks. The SSL tool will generate the file with line breaks so make sure you remove them all and make it one long file.

Save these changes and in an hour or so (up to 48 hours in on a bad day) this TXT record will be live.

Step 3 – Sending the private key with an email
This part very much depends on your programming language and the email client you are using with that programming language.

So for example if you are using PHPMailer, you can setup the private DKIM key by adding the following lines to your code

So this is it, you are finished! Not so bad right? May take a while for the updates to show up since DNS zone file changes can take a while to update across the internet, but once they do you will be all set with DKIM keys correctly setup for your emails. Remember that this is only 1 method of improving the odds of your emails not ending up in a spam folder, but doesn’t guarantee it. You may also need to setup a reverse lookup in order to make yourself 100% safe.