How to Verify Email Address Using Php Codeigniter

140

In User registration process, most of the time user enters wrong Email Id or Junk email Id to prevent this we are going to actually verify the user email address by sending the verification code on his/her email id. Let have a closer how to do this using Php Codeigniter

Create Database table

First of all you need to create simple user details table “trn_user” in mysql database with the help of below sql script. This table contain User details like first name , last name, email id, and email verification code.

Insert few records in the above table, But make sure that column value of “email_verification_code” should be unique. Base on this unique value we are going to verify the user email address

Controller Class(Home.php)

Home.php is the controller class in Php Codeigniter. Which is used to sent the email and verify the email address. There are two methods sendVerificationEmail() and verify(). In sendVerificationEmail() method I have not covered complete code, used hard coded values which is mapped to trn_user table.

As per your need you can make it dynamic to send email to users after user registration. Once the user received verification email in his/her mailbox. Then user need to click on verification link to complete the verification process.

One small important thing you need to do here. Map your verify method of Home controller using roting. Add below Entry in routes.php file which is located under folder name “system/application/config/routes.php”

Sample Verification Email look like below Image.Base on verification you can display the approprivate error message on view page.

Create Email Model(EmailModel.php)

This Emailmodel is used to sent emails to User along with the unique email verification code. In below code you need to do some smtp configuration changes like host_name, port, smtp_user and password etc.

Create Home Model

Base on verification code we are going to update the User Status active_status column value.

 

Leave A Reply

Your email address will not be published.