php tutorial - Email Verification in PHP for Registered User - php programming - learn php - php code - php script



To verify an authorized user registration and to avoid duplicacy in accounts of users for an organization, it becomes very important to verify his/her identity. For this, a common way of email id verification is used for registered user, which was pre-stored in organisation’s database when he/she was registered for the first time.

This blog post concerns about “Email Verification” and explains you how it is done using PHP.

We have used PHP script to verify particular email, in which following steps were performed:

  • Establish connection with server.
  • Selecting Database.
  • SQL Query to fetch records from table.
  • Matches input values with query returned values.
  • Connection Close.

We have created our database and stored an email “fugo@wikitechy.com” with name “fugo” when above PHP script executes values from input field matches with pre-stored email id and name in database, if match found then it will notify as “verification successful” .

 email-verification-in-php

Learn php - php tutorial - email-verification-in-php - php examples - php programs

Below is our complete code with download and live demo option

PHP File: checkemail.php

In this file you will find combination of HTML and PHP, main functionality of the code has written in PHP segment.

<!DOCTYPE html>
<html>
<head>
<title>PHP Email Verification Script</title>
<link href="css/style.css" rel="stylesheet">
</head>
<body>
<div id="mainform">
<div id="innerdiv">
<!-- Required Div Starts Here -->
<h2>PHP Email Verification</h2>
<form action="" id="form" method="get" name="form">
<h3>Email Verification Form</h3>
<label>Name :</label>
<input id="name" name="name" placeholder="Name" type="text">
<label>Email :</label>
<input id="email" name="email" placeholder="Email" type="text">
<input id="submit" name="submit" type="submit" value="Verify">
<div id="alert">
<?php
if (isset($_GET['submit'])) {
if (empty($_GET['name']) || empty($_GET['email'])) {
echo '<span id="one">***Fill All Fields***</span>';
} else {
$name2 = $_GET['name'];
$email2 = $_GET['email'];
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("company", $connection); // Selecting Database
$query = mysql_query("select * from member where emp_email='$email2'", $connection); // My-SQL Query to fetch particular matching row.
$rows = mysql_num_rows($query);
if ($rows == 1) {
echo '<span id="two">***Email Verification Success***</span>';
} else {
echo '<span id="three">***Email Verification Failed***</span>';
}
mysql_close($connection); // Closing Connection with Server
}
}
?>
</div>
</form>
</div>
</div>
</body>
</html>
click below button to copy the code. php tutorial - team

CSS FIle: style.css

Style of HTML elements is defined here.

/*----- Below line is to import Google fonts in our page. -------------*/
@import "http://fonts.googleapis.com/css?family=Fauna+One|Muli";
/*---------- CSS For the required HTML elements---------*/
#mainform{
width:960px;
margin:30px auto;
padding-top:20px;
font-family:'Fauna One',serif;
text-align:center
}
#mainform h2{
width:480px
}
#form{
background-color:#fff;
color:#123456;
box-shadow:0 1px 1px 1px gray;
font-weight:400;
width:480px;
margin:70px 0 0;
height:300px
}
h3{
margin-top:0;
color:#fff;
background-color:#1CC32B;
text-align:center;
width:100%;
height:50px;
padding-top:30px
}
input{
width:300px;
height:30px;
margin-top:10px;
border-radius:3px;
padding:2px;
box-shadow:0 1px 1px 0 #a9a9a9
}
input[type=submit]{
background-color:#1CC32B;
border:1px solid #fff;
font-family:'Fauna One',serif;
font-weight:700;
font-size:18px;
color:#fff;
margin-left:60px
}
#message{
width:100%px;
margin-top:50px;
font-size:14px
}
#alert{
margin-top:10px
}
#one{
padding:5px;
color:red
}
#two{
padding:5px;
color:green
}
#three{
padding:5px;
color:red
}
#innerdiv{
float:left;
width:50%;
height:500px;
padding:50px 30px 30px;
margin-top:30px
}
click below button to copy the code. php tutorial - team


Related Searches to Email Verification in PHP for Registered User