In last article we have learned How to Create Registration Form with PHP and MySQLi. Now you might be looking for that How to send a email confirmation link or email to newly registered user in order to prevent from spamming. So here I am going to show you that how we can send confirmation email to newly registered user. Here we need to table one for ‘users’ and the other one if for ‘confirmation’. So here are the structure for table tables.

Live DemoDownload

For table ‘users’

This is same table that we have made in our previous article in which we learn How to Create Registration Form with PHP and MySQLi. We have just added a new field ‘status’ to determine whether the email is activated or not.

For table ‘confrim

Logic Behind Them

Now lets have a look on logic behind all process. First when user input his email, password and username. We insert these data into table ‘users‘ and the field status by default will be 0 (zero). Now we generate a unique key and add this key to table ‘confirm‘ along with user input email. After this process we send an email to user’s entered email with confirmation link. When user open that link it redirects to new page where the key is being checked. If the key matched with any of row in database, it fetch email field of that matched row and went to table ‘users‘ and searched for respective email record and UPDATE status of that record to 1. This is simple logic behind this process.

Let’s move towards code.

config.php this file contain basic database connection detail.

$url is the basic variable in which I have stored website address.

index.php this file contain basic HTML Form and some PHP Code

Basic HTML form. In my case it includes only an email and a password field.

Now let’s see PHP Code. Obviously we have to perform action when user hit Submit button, so in PHP we can do it as:

Now lets check if user enter a valid format of email. So,

If user has not entered valid format email address it will show him an error “Invalid email format”. Otherwise it will move to next portion of code. Here, we will first check that whether the entered email is already existing in database or not. If it exist it show error “Sorry…This email already exist.” Otherwise will move ahead. Here is the code to check existence of email in database:

Live DemoDownload


  1. Very good I am always benefited from your lessons .. I hope I will be in touch with you even send you my questions .. Where the rest of the lesson?

  2. Thanks downloading it a must to use a gmail account for the php mailer for sending the email

  3. Hello, how am i to use this email script with the registration in such a way that the user has to verify his email before login

  4. First you have to create a registration page on your site just like i created here. Then in login page check whether email verification column is true or false in case of true login user successfully otherwise print error.

Leave a Reply