User Registration with Email Verification using PHP and Mysql


I had receive a tutorial request from one of my blog follower to make or demonstrate User Registration with Email Verification using PHP and Mysql. So the flow is quite simple, user registers to a site, and email is sent to their email address for verification. User then click a link in the email message which redirect him back to the site where it’s account gets approved. I have used php-mailer library so you can send mail via your google account from your local server itself.

View Demo

Create a database with user table

The first thing you have to do is to create your database and table where the records can be stored. Use the sql script below.

Setup a form with four fields username, email, password and confirm password. just to be extra sure of the password.

Validation and user registration code with PHP and Mysql

I am skipping the client side validation with javascript, it is there in the demo and the download scripts. When the user submits the form it’s a two step process. First we check if any existing email id is present in the database, if yes we don’t proceed further, if no then we insert the values in the database and send an email to the user. The user status will be pending until user verify their email. See the code to insert the user record below.

Sending mails using your Google account from your local/online server using phpmailer

For sending mail to user you can use php mail function. But that doesn’t work most of the time in your local server. There’s an excellent plugin I use in most of my project “PHPMAILER“. You can send good looking HTML email with your Gmail or any other mail account via SMTP. All you have to do it so set up your email id, password and host and port name.

Approving user registration process from email

The final part is approving the user. When you are sending email to the user, add the user ID that you recieve when you insert the record in the database. So when user hit the link it will be redirected back to your site with the user ID. You can then use that user ID and update the database.

View Demo


About Author

Entrepreneur & Dreamer

I am a passionate Software Professional, love to learn and share my knowledge with others.

Software is the hardware of my life.


  1. Nitish Kasar on

    good Script bro, especially liked the validation and prepared SQL methods thanks for sharing …. Keep it up

  2. thanx for ths script
    but it shows following error

    Fatal error: Undefined class constant ‘MYSQL_ATTR_INIT_COMMAND’ in C:\wamp\www\email-verification-php-mysql\config.php on line 22

  3. Hello sir all are working proper till last but in last it gives error
    after clicking email for action

    it give to

    Hi devendra!

    and when i click to active link it gives error

    Object not found!

    The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

    If you think this is a server error, please contact the webmaster.

    Error 404

    Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3

    • In your configuration.php,

      change this line into your own URL

      define(‘SITE_URL’, ‘http://your_own_URL’);

      so when you click on “CLICK TO ACTIVATE YOUR ACCOUNT”, it will redirect you to you own “activation” page.

  4. how can i check username and email availability both using this code, i tried but im getting error cannot use try without catch or finally…please help..

  5. will you tell me how to check duplicate email address exit in database or not at the time of registration

  6. Stan Smith Adidas on

    Why viewers still use to read news papers when in this technological
    globe everything is accessible on net?

  7. I Keep getting SMTP ERROR: Failed to connect to server: (0) SMTP connect() failed.
    I’m currently hosted not using local server.

  8. hello!
    my program is working properly but i could not get an email in my email id. which i entered at time of registration.

Leave A Reply

CommentLuv badge

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.