In this tutorial we will create 4 PHP Scripts files and one Database.
- signup.html
- sgnup_action.php
- confirmation.php
- config.php
Note that this is not necessary, you can change the scenario. This all is just to provide you a simple concept that how you can verify an email using php.
First of all create a database with name “users”.
Next step to proceed is to write code for config.php file. Code is :
1 2 3 4 5 6 |
$host = 'localhost';
$user = 'abc';
$pwd = 'your_password';
$db = 'database';
$conn = mysql_connect($host,$user,$pwd);
mysql_select_db($db,$conn);
|
We are all done with the config.php, now we have to simply design a simple registration form for that. This file would be named as ‘signup.php’
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<body>
<form action="signup_action.php" enctype="multipart/form-data" name="form" id="form" method="post">
<table width="200" border="0">
<tr>
<td>Name:</td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password" id="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</table>
</form>
</body>
|
After that is to develop a code that will enter the user information into the database along with a confirmation key and the initial status of the user is ‘0’ it means that user is not active yet.
Once I filled the form and press submit button.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
//======Include Files
include('config.php');
//================ Variables=======
$name = $_POST['name'];
$email = $_POST['email'];
$password= $_POST['password'];
$confirm_code=md5(uniqid(rand()));
$status = 0;
if(isset($_POST['submit']))
{
// =====Form Validation=====
if($password!=''&&$email!='')
{
//====To test if email already exists===
$query = "SELECT * FROM users WHERE email='$email'";
$res = mysql_query($query);
if(mysql_num_rows($res)>0)
{
echo '<h3 style="color:red">This email is Already Registered</h3>';
}
$query = "INSERT INTO users(name,email,password,status,confirm_code)VALUES('$name','$email','$password','$status','$confirm_code')";
$res = mysql_query($query);
if($res)
{
// send e-mail to ...
$to=$email;
// Your subject
$subject="Your confirmation Link";
// From
$header="from: Nidfo Administrator";
// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$host = $_SERVER['HTTP_HOST'];
$message.="http://$host/examples/email_verification/confirmation.php?passkey=$confirm_code";
// send email
$sentmail = mail($to,$subject,$message,$header);
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
}
}
}
else
{
}
|
I have received an email with a link from where I can activate my account. At the start, situation of the table is also shown below.
Random Posts








