Skip to content

kr123Manish/Simple_email_verification_form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Overview

Creat a form which verify email using OTP (One Time Password)

------------------------------------------------------------------------------------

-----------------------------------------------------------------------------------------

Prerequisite

  • HTML-5
  • CSS
  • PHP

Little discussion about main code.

<?php
  // <-------------------------------------------------------------------------------------->
  // Part of getting OTP.
  // Get value from post method when click on GET OTP buttoon.
  if (array_key_exists("getotp",$_POST)) {
    // echo "Ready for otp";
    if (!$_POST["email"]) {
        $eerror="Email is required";  //Check email is filled or not.
    }else{    $code=rand();       //Create a randome number using rand() function.
              session_start();    //Session start for store that code.
              $_SESSION[$vcode] =$code; //Value is stored.

            $emailTo=$_POST['email'];   //Get user email using Post method and store in email variable.
            $Subject="Email OTP";       //Subject of email
            $body="Your One Time Password is: ".$code;    // Body part of message and OTP.
            $header="Verify your email";              //Header part of email.
            if(mail($emailTo,$Subject,$body,$header)){
              $success='mail sent sucessfully.';        // If OTP sent success message  save.
              
            }
            else{
              $error='mail did not sent';     // If mail unable to sent error message save.
            }
    }
  }
  
  //<-------------------------------------------------------------------------->
  // verify email
  if(array_key_exists("submit",$_POST)){    //if submit button sent post request.
    // echo "Ready for verify otp";
    if (!$_POST["email"]) {
        $eerror="Email is required";    // if email does not filled then this error display.
    }
    if (!$_POST["otp"]) {
      $oerror="Fill the OTP";     // // if OTP does not filled then this error display.
    }else{
      // echo "Email Verified successfully";
      session_start();
       $code=$_SESSION[$vcode];
    
      if ($_POST["otp"]==$code) {
          $success="Mail verfied";    // if otp matches with code then mail verified message appears.
      }else{
        $oerror= "Your otp is invalid";   // of otp does not matches then error message appears.
      }
    }
  }
?>

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published