EMail Verification Script in PHP for Registered User

In this tutorial, you will learn about verifying user email address while user registration. This is continuation part to user registration script. Here, I’m generating a verification code based on username input field value submitted by the user. Because this username is unique.

Next sending this verification code through email for that user as a link. If the user clicks on that link, their account will be verified. I’m using PHPMailer to send emails through SMTP login credentials. If you don’t know how to use PHPMailer, follow this tutorial – How to Use PHP Mailer.

Generate verification key based on username, use this code right after username variable

Then modify sql query to insert verification_key value in database table. Before that alter databse table & create verfication_key column with varchar type.

After successfully instering data into table, I’m going to send email. Before that donwload PHPMailer from github.

Include PHPMailerAutoload.php file in our register.php file.

Then create a file with name of config.php to store smtp credentials.

Include this config.php file in register.php file

Send email using PHPMailer Library, if the record is succesfully inserted.

Till now we are able successfully sending email. Next we have to create verify.php file to update user record active column to 1. That is making user active.

connect to databaase in verify.php file and assign key value from url to variable.

Then using SELECT sql query, check if the verification key exists in database. If the count return one update the records active column value to 1.

Using UPDATE query to update active column.

Complete Code of EMail Verification Script

If you have any problem arranging above pieces of code, you can use this complete code.

If you have any problem, let me know through comment form below.

Vivek Vengala
 

Vivek Vengala is a Online Entrepreneur, Web Developer from Hyderabad India.

Click Here to Leave a Comment Below 0 comments

Leave a Reply: