Friday, 10 June 2022

PHP Email verification Code example

 (1)first create table user:


create table user
(id int primary key auto_increment,

name varchar(200),
email varchar(200),
phone varchar(200),
password varchar(200),
com_code varchar(200));


(2)write code for connect.php file:

<?php

$con=mysqli_connect("localhost","root","","database");


?>

(3)write code for registerform.php file:
<?php


echo '<form action="insert1.php"   method="post">
      Name<input type=text name="name">
  Email<input type=email name="email">
  phone  <input type=text    name="phone">
  password<input type=password name="password">
  <input  type=submit  name=submit value=submit>';
 
  
?>

(4)write code for insert1.php file:



<?php
$name=$_POST['name'];
$email=$_POST['email'];
$phone=$_POST['phone'];
$password=$_POST['password'];
$com_code=md5(uniqid(rand()));
include_once("connect.php");

$sql="insert into user(name,email,phone,password,com_code)values('$name','$email','$phone','$password','$com_code')";

$result=mysqli_query($con,$sql) ;

if($result)
  {
   $to = $email;
   $subject = "Confirmation from Musaib to $username";
   $header = "Musaibwebsite: Confirmation LInk";
  
   $message .= "http://musaib.com/confirm.php?passkey=$com_code";

   $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";
   }

}

?>

(5)write code for confirm.php file:

<?php

include_once("connect.php");

$passkey = $_GET['passkey'];

 $sql="update user set com_code='1'  where com_code='$passkey'";

$result=mysqli_query($con,$sql) ;

if($result)

{


echo "your account is active ";




}



?>

No comments:

Post a Comment