User Registration with Email Verification using PHP and Mysql -PHPMailer




Simple User Registration Email Verification script with Php Mailer-



Hello friends ajj me apko btaunga ki ham kis parkar email verification php script  create kar sakte hai ,jo ki bhut jarruri hai kisi be php project ke liye.

Steps for php email verification scripts-

PHPmailer+mysql+php-
Yanha ham 3 things ka use karege
Phpmailer ka use mail bhejne ke liye means verification link user ki email id par bhejne ke liye (aap mail function ya swiftmailer be use kar sakte ho)
Mysql ka use user information ko database me store karne ke liye
Php-php ka use form create karne ke liye means sara dynamic form work karne ke liye.

app bootstap and css ka use karke ise mobile responsive and stylish be bana sakte ho



index.php







<?php

include_once("config.php");

$ms='';

if(isset($_POST['submit']))

{

$name=$_POST['name'];

$email=$_POST['email'];

$password=md5($_POST['password']);

$status=0;

$activationcode=md5($email.time());









$query=mysqli_query($con,"insert into users2(name,email,password,activationcode,status) values('$name','$email','$password','$activationcode','$status')");









require 'PHPMailer-master/PHPMailerAutoload.php';



$mail = new PHPMailer();

  

  //Enable SMTP debugging.

  $mail->SMTPDebug = 0;

  //Set PHPMailer to use SMTP.

  $mail->isSMTP();

  //Set SMTP host name

  $mail->Host = "smtp.gmail.com";

  $mail->SMTPOptions = array(

                    'ssl' => array(

                        'verify_peer' => false,

                        'verify_peer_name' => false,

                        'allow_self_signed' => true

                    )

                );

  //Set this to true if SMTP host requires authentication to send email

  $mail->SMTPAuth = TRUE;

  //Provide username and password

  $mail->Username = "yourgmailid";//enter your gmail here

  $mail->Password = "gmailpassword";//enter your gmail password here

  //If SMTP requires TLS encryption then set it

  $mail->SMTPSecure = "false";

  $mail->Port = 587;

  //Set TCP port to connect to

  

  $mail->From = "kashyapbhupender122@gmail.com";

  $mail->FromName = "jignesh";



  $address = $_POST['email'];

$mail->addAddress($_POST['email']);

  

  $mail->isHTML(true);

$mail->addAttachment('sonu.txt'); //set new name

$mail->addAttachment('kunal.txt'); //set new name

$mail->Subject    = "emailverification";



$mail->Body ="<div style='padding-top:8px;'>Please click The following link For verifying and activation of your account</div>

<div style='padding-top:10px;'><a href='http://localhost/emailverification/teest/email_verification.php?code=$activationcode'>Click Here</a></div>

<div style='padding-top:4px;'> <?php $password; ?></div></div>";









  $mail->AltBody = "This is the plain text version of the email content";

  if(!$mail->send())

  {

   echo "Mailer Error: " . $mail->ErrorInfo;

  }

  else

  {

   echo "<h1>varification email send on email id successfully please check Your email Id and Verifiy </h1>";

  }

}

?>


<fieldset>



<form name="insert" action="" method="post">

<h1>Signup Form With Email Verification With PhpMailer</h1>

<br>





<input type="text" name="name" id="name" value=""  class="form-control" required />



<br>

<input type="email" name="email" id="email" value=""  class="form-control" required />

<br>

<input type="password" name="password" id="password" value=""  class="form-control" required />



<br>

<input type="submit" name="submit" value="Submit" class="btn-group-sm" />



</form>

</fieldset>


Inbox.php file me hamne signupform banaya hai yanha php mailer ka use kiya gya hai phpmailer user ke email id par ek verification link send karega.

yanha apko apni gmail id and password enter karna hai or sath he jo link ham send kar rahe hai uski uski location change karle jo be apne apne project ka name hai




email_verification.php






<?php

$msg='';

include 'config.php';

if(!empty($_GET['code']) && isset($_GET['code']))

{

$code=$_GET['code'];

$sql=mysqli_query($con,"SELECT * FROM users2 WHERE activationcode='$code'");

$num=mysqli_fetch_array($sql);

if($num>0)

{

$st=0;

$result =mysqli_query($con,"SELECT id FROM users2 WHERE activationcode='$code' and status='$st'");

$result4=mysqli_fetch_array($result);

if($result4>0)

{

$st=1;

$result1=mysqli_query($con,"UPDATE users2 SET status='$st' WHERE activationcode='$code'");

$msg="Your account is activated";

}

else

{

$msg ="Your account is already active, no need to activate again";

}

}

else

{

$msg ="Wrong activation code.";

}

}

?>



<?php



echo "Your Account Is Activated Succesfully";

header("location:login.php");





?>

email_verication.php file ka work account ko activate karna hai means jab user email verication link jo uski email id me aya hoga us par click karega to wanha parr ye file execute hogi or user ke account ko activate kar degi.jab user ne signup kiya tha to uska status 0 store hua tha database me ……yanha hamne ek query ka use kiya hai login.php file me ki agar user ka status 1 hoga tbhi wo login kar payega….to email_verication.php file ka kam hai ki jab user verication link par click karega to ye file user ke account me status 0 ko 1 me update kar degi jiske karn user ka account activate ho jayega or user login kar payega.



config.php


<?php

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

?>


config.php file ka work database connection banana hai



logout.php

<?php

session_start();

$_SESSION['login']=="";

session_unset();

$_SESSION['action1']="You have logged out successfully..!";

?>

<script language="javascript">

document.location="login.php";

</script>





Logout.php ka use logout karne ke liye kiya gya hai





welcome1.php




<center>



<?php

session_start();

include_once("config.php");

if($_SESSION['login'])

{

?>


Welcome  User This is admin pannel:

    <font color="red"><?php echo $_SESSION['name']; ?></font> ||   <a href="logout.php">Logout</a>

<?php

} else {

header('location:logout.php');

}



?>

</center>

welcome1.php file user ke welcome ke liye hai jab be user correct email id and password dalker login hoga





login.php



<?php

session_start();



include_once("config.php");

if(isset($_POST['login']))

{

$email=$_POST['email'];

$password=$_POST['password'];







$ret= mysqli_query($con,"SELECT * FROM users2 WHERE email='$email' and password='$password'");

$num=mysqli_fetch_array($ret);

$status=$num['status'];

if($num>0)

{

if($status==0)

{

echo "Verify  your Email  click  on the link In your inbox email";

}

else {

$_SESSION['login']=$email;

$_SESSION['id']=$num['id'];

$_SESSION['name']=$num['name'];



header("location:welcome1.php");

exit();

}

}

else

{

echo "Invalid username or password";

header("location:login.php");

exit();

}

}

?>

<fieldset>

<center>

<h1>Login Page</h1>

<form action="" method="post">

    

    

  

<br>

    

   email <input type="email" name="email" id="email" value=""  class="form-control" required />



  <br>

   password<input type="password" name="password" id="password" value=""  class="form-control" required />

<br>

  

   <input type="submit" name="login" value="Submit" class="btn-group-sm" />



</form>

</center>

</fieldset>

Login.php ka use login karne ke liye kiya gya hai …agar user ne email verication link jo uski email id par aya hai us par click karne ke bad login  karega tbhi user ka account activate hoga or wo login kar payega .



App niche diye gye link se complete email veriication script download kar lijiye apko iske sath databse file be mil jayegi jise sirf apko apne database me import karna hai




Download Php Email Verification Script





Note-yanha jab be aap login karo to username me apni email id enter karna and password me apke mysql databse me store hua md5 password formate ka use karke login kare

Thank You

Team Gajabwap Web In Hindi




Previous
Next Post »

1 comments:

Click here for comments
Unknown
admin
10 February 2022 at 01:19 ×

login logout system with the full coding in php send me sir

Congrats bro Unknown you got PERTAMAX...! hehehehe...
Reply
avatar
Thanks for your comment