Email Confirmation Concept | Sanwebcorner

Email Confirmation Concept

This post i am explain about how to check the confirmation from email , it is very simple and easy to identify the customer email verification code. In this concept first we are going to register the details of the customer and the action.php is taken care for registering those user details in tempuser and it sent the confirmation link to the customer email, It will take the customer email from form . after customer click the confirmation link the confirmation.php is register the data in reguser table. and then the user account will be activated.

Registration process:


email confirmatin concept

The confirmation link sent to your mail id


email-confirmation

click confirmation code


email-confirmation

Activate Your account


email-confirmation


Code:

Database and Table:


--
-- Database: `sanwebcorner`
--

CREATE TABLE IF NOT EXISTS `tempuser` (
  `confirm_code` varchar(65) NOT NULL DEFAULT '',
  `name` varchar(65) NOT NULL DEFAULT '',
  `email` varchar(65) NOT NULL DEFAULT '',
  `password` varchar(15) NOT NULL DEFAULT '',
  `country` varchar(65) NOT NULL DEFAULT ''
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

CREATE TABLE IF NOT EXISTS `reguser` (
  `id` int(4) NOT NULL AUTO_INCREMENT,
  `name` varchar(65) NOT NULL DEFAULT '',
  `email` varchar(65) NOT NULL DEFAULT '',
  `password` varchar(65) NOT NULL DEFAULT '',
  `country` varchar(65) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;


index.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Send Email Confirmation code</title>
<style type="text/css">
.san
{
margin-left:auto;
margin-right:auto;
border:1px solid #CCC;
border-radius:25px;
width:400px;
padding:35px;
}
</style>
</head>

<body>
<div class="san">
<table width="350" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><form name="form1" method="post" action="action.php">
<table width="100%" border="0" cellspacing="4" cellpadding="0">
<tr>
<td colspan="3"><strong><h2 style="text-decoration:underline;">Send Email Confirmation code</h2></strong></td>
</tr>
<tr>
<td width="76">Name</td>
<td width="3">:</td>
<td width="305"><input name="name" type="text" id="name" size="30"></td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td><input name="email" type="text" id="email" size="30"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password" size="30"></td>
</tr>
<tr>
<td>Country</td>
<td>:</td>
<td><input name="country" type="text" id="country" size="30"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> &nbsp;
<input type="reset" name="Reset" value="Reset"></td>
</tr>
</table>
</form></td>
</tr>
</table>

</div>
</body>
</html>

action.php


<?php

include('db.php');


$tbl_name=tempuser;


$confirm_code=md5(uniqid(rand())); 


$name=$_POST['name'];
$email=$_POST['email'];
$country=$_POST['country'];


$sql="INSERT INTO $tbl_name(confirm_code, name, email, password, country)VALUES('$confirm_code', '$name', '$email', '$password', '$country')";
$result=mysql_query($sql);


if($result){



$to=$email;


$subject="Your confirmation link here";


$header="from: your name <your email>";


$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="your url/confirmation.php?passkey=$confirm_code"; // put your url here


$sentmail = mail($to,$subject,$message,$header);
}


else {
echo "Not found your email in our database";
}


if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
?>


confirmation.php


<?php

include('db.php');


$passkey=$_GET['passkey'];
$tbl_name1="tempuser";


$sql1="SELECT * FROM $tbl_name1 WHERE confirm_code ='$passkey'";
$result1=mysql_query($sql1);


if($result1){


$count=mysql_num_rows($result1);


if($count==1){

$rows=mysql_fetch_array($result1);
$name=$rows['name'];
$email=$rows['email'];
$password=$rows['password']; 
$country=$rows['country'];
$tbl_name2="reguser";


$sql2="INSERT INTO $tbl_name2(name, email, password, country)VALUES('$name', '$email', '$password', '$country')";
$result2=mysql_query($sql2);
}


else {
echo "Wrong Confirmation code";
}


if($result2){

echo "Your account has been activated";

$sql3="DELETE FROM $tbl_name1 WHERE confirm_code = '$passkey'";
$result3=mysql_query($sql3);

}

}
?>

db.php

<?php

$host=""; //host name
$username=""; //mysql username
$password=""; //mysql password
$db_name="";  // mysql database name

mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); 
mysql_select_db("$db_name")or die("cannot select DB");

?>

Download Code