How To Create Emails Activation Form With PHP Script

Share:

Tutorial : How To Create Email Activation Form With PHP Script. If you register on a social networking and other sites, we usually will get the activation email and asked to click on the activation link to activate our membership. The activation email is very important to ensure that the registered email is an active email and really belongs to the registrant as a way of avoiding spammers attack.
How To Create Email Activation Form With PHP Script How To Create Email Activation Form With PHP Script

Tutorial : How To Create Email Activation Form With PHP Script

Actually not difficult to create an email form such activation because we can use php script. You want to know how to create an email activation form with php script ? Follow the tutorial to create activation email below :

Download Now How To Create Emails Activation Form With PHP Script - How To Create Emails Activation Form With PHP Script

1. Create MySQL Table

First we have to create a table in the database on the phpnyadmin server hosting. This table stores, id, username, password, email, activation code or activation checks. When the activation command is executed, the data and the activation code that is stored in the table will be in the match. If the results are the same then the activation process will be deemed to have been successful.

CREATE TABLE 'email_activation' (
  'id' int(11) NOT NULL auto_increment,
  'username' varchar(25) NOT NULL,
  'email' varchar(25) NOT NULL,
  'password' varchar(25) NOT NULL,
  'activation' int(6) NOT NULL default '0',
  'check_activation' int(6) NOT NULL default '0',
  PRIMARY KEY  ('id')
) ;

2. Create Registration Form

To get the data from the registries required a registration form that data will be stored into the table that has been created. Here’s the registration form and you can modify according to your wishes.
index.html

<style type="text/css">
<!--
.style1 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 12;
}
.style5 {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 16px;
	font-weight: bold;
}
.style7 {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
-->
</style>
<form name="form1" method="post" action="email-activation-script.php">
  <div align="center">
    <p class="style5"> Form Registration </p>
    <table width="35%" border="0">
      <tr>
        <td class="style7">Username</td>
        <td class="style7">:</td>
        <td class="style1"><span class="style7">
          <label>
          <input name="username" type="text" id="username">
          </label>
        </span></td>
      </tr>
      <tr>
        <td class="style7"> Email </td>
        <td class="style7">:</td>
        <td class="style1"><span class="style7">
          <label>
          <input name="email" type="text" id="email">
          </label>
        </span></td>
      </tr>
      <tr>
        <td class="style7">Password</td>
        <td class="style7">:</td>
        <td class="style1"><span class="style7">
          <label>
          <input name="password" type="password" id="password">
          </label>
        </span></td>
      </tr>
      <tr>
        <td class="style7">&nbsp;</td>
        <td class="style7">&nbsp;</td>
        <td class="style1"><span class="style7">
          <label>
          <input type="submit" name="Submit" value="Register">
          <input type="reset" name="Submit2" value="Cancel">
          </label>
        </span></td>
      </tr>
    </table>
  </div>
</form>

3. Create Activation Email with PHP Script

We’ve made a MySql table and also the registration form, then, we create an activation email with the help of php scripts that will be sent to registrants. This is php script for activation email :
email-activation-script.php

<?php
$username=$_POST['username'];
$email=$_POST['email'];
$password=$_POST['password'];
$db_host = "localhost";
$db_name = "databasename";
$db_use = "root";
$db_pass = "password";
$link = mysql_connect($db_host, $db_use, $db_pass);
mysql_select_db($db_name, $link);
$chars = array("1","2","3","4","5","6","7","8","9");
$length = 6;
$textstr = "";
for ($i=0; $i<$length; $i++) {
   $textstr .= $chars[rand(0, count($chars)-1)];
}
$query = "INSERT INTO email_activation (username, email, password, activation) VALUES ('$username','$email','$password','$textstr')";
$result = mysql_query($query);
if ($result) {
echo "Successfully...<br>";
$mail_to="$email";
$mail_subject="Email Activation";
$mail_body = "This is the email to activate your account.\n";
$mail_body.="Your activation code is: $textstr \n";
$mail_body.="Click the following link to activate your account.\n";
$mail_body.="<a href='activation-form.php?username=$username&activation=$textstr'>Click here</a>";
//$sent = mail($mail_to,$mail_subject,$mail_body, "From: yourmail@domain.com");
echo "$mail_to<br><b>$mail_subject</b><br><br>$mail_body";
}else{
echo "Failed to sent email activation code";
}
?>

4. Create Activation Form

The next step is to create a form to enter the activation code from activation code which has been sent via email. Here is the activation form :
activation-form.php

<form name="form1" method="post" action="check-activation-script.php">
  <div align="center">
    <table width="35%" border="0">
      <tr>
        <td>Username</td>
        <td>:</td>
        <td><label>
          <input name="username" type="text" id="username">
        </label></td>
      </tr>
      <tr>
        <td>Activation Code </td>
        <td><label>:</label></td>
        <td><input name="activation_code" type="text" id="activation_code"></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><label>
          <input type="submit" name="Submit" value="Submit">
          <input type="reset" name="Submit2" value="Cancel">
        </label></td>
      </tr>
    </table>
  </div>
</form>

5. Create Activation Check with PHP Script

The final step is to create an activation form to ascertain whether they suited with activation code that exists in the database. If the activation code is same, so registration has been successfully carried out and this is the php script:
check-activation-script.php

<?php
$username = $_POST['username'];
$activation_code = $_POST['activation_code'];
$db_host = "localhost";
$db_name = "databasename";
$db_use = "root";
$db_pass = "password";
$link = mysql_connect($db_host, $db_use, $db_pass);
mysql_select_db($db_name, $link);
$command = "UPDATE email_activation SET check_activation='$activation_code' WHERE username='$username' and activation='$activation_code'";
$result = mysql_query($command);
if ($result) {
echo "Congratulations. Your membership has been activated ...";
}else{
echo ("You've entered an invalid username / activation code - please retry");
}
?>

I think this php script to create email activation is still very simple and a lot of shortcomings. Next time, I will continue to refine how to create email activation because the php script to make email activation is very important especially for those of you who are currently developing a site that receives registration.
I hope this tutorial can be useful to you and thank you for reading How To Create Email Activation Form With PHP Script

[Tutorial.World.Edu]

11 thoughts on “How To Create Emails Activation Form With PHP Script

Leave a Reply

Your email address will not be published. Required fields are marked *