How to Account Verification System Through Email Using PHP

So the flow is quite simple, user registers to a site, and email is sent to their email address for verification. User then click a link in the email message which redirect him back to the site where it’s account gets approved. You may also like How to Check UserName and Email Availability From Database using PHP and Ajax.


<!DOCTYPE html>
    <form method="post" action="submit.php">
        <input type="email" name="email" required="">
        <input type="password" name="password" required="">
        <input type="submit" name="register" Value="Register">

PHP Code

    $email_id=  $_POST['email'];
    $pass=  $_POST['password'];

    $insert = mysqli_query($conn,"insert into verify(email,password,code)values($email','$pass','$code')");
    $db_id = $conn->insert_id;

    $message = "Your Activation Code is ".$code."";
    $to = $email;
    $subject = "Activation Code For";
    $from = '';
    $body='Your Activation Code is '.$code.' Please Click On This link submit.php?id='.$db_id.'&code='.$code.'to activate your account.';
    $headers = "From:".$from;
    echo "Email Send please verify your account";

Click on Email Link

if(isset($_GET['id']) && isset($_GET['code']))
    $select=mysqli_query($conn,"select email,password from verify where id='$id' and code='$code'");
    if(mysqli_num_rows($select) > 0)
        $insert_user = mysqli_query($conn,"insert into verified_user (email,password) values('$email','$password')");
        $delete      = mysqli_query($conn,"delete from verify where id='$id' and code='$code'");

Leave a Reply

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