Php Mail Doğrulama Kodu

Php Mail Doğrulama Kodu

Php Mail Doğrulama Kodu

PHP mail kontrol nasıl yapılır Php İle E Posta (Mail) Kontrolü hakkında bilgi Mail geçerlilik kontrolü kodları verilmiştir.

Bu eğitimde, kayıtlı bir e-posta kimliğini PHP PDO uzantısını kullanarak nasıl doğrulayacağımızı öğreneceğiz .

Bu öğretici aşağıdaki dosyaları içerir 1.
Kayıt dosyası (index.php) 2. E-posta
Doğrulama dosyası (email_verification.php) 3.
Giriş dosyası (login.php)
4. Hoş geldiniz dosyası (welcome.php)
5. Çıkış dosyası (logout.php )
6.Database Bağlantı (config.php)
Veritabanı bir tablo (userregistration) dahil
userregistration MySQL tablosunun yapısı

CREATE TABLE IF NOT EXISTS `userregistration` (
  `id` int(11) NOT NULL,
  `name` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `activationcode` varchar(255) NOT NULL,
  `status` int(11) NOT NULL,
  `postingdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

İlk olarak, kullanıcı kaydı HTML formu oluşturacağız.

<form name="insert" action="" method="post">
<table width="100%"  border="0">
<tr>
<th height="62" scope="row">Name </th>
<td width="71%"><input type="text" name="name" id="name" value=""  class="form-control" required /></td>
</tr>
<tr>
<th height="62" scope="row">Email id </th>
<td width="71%"><input type="email" name="email" id="email" value=""  class="form-control" required /></td>
</tr>
<tr>
<th height="62" scope="row">Password </th>
<td width="71%"><input type="password" name="password" id="password" value=""  class="form-control" required /></td>
</tr>
<tr>
<th height="62" scope="row"></th>
<td width="71%"><input type="submit" name="submit" value="Submit" class="btn-group-sm" /> </td>
</tr>
</table>
</form>

Veri eklemek veya doğrulama postası göndermek için PHP kodu. Bu kodu index.php'nin en üstüne koyun

<?php include_once("config.php");
if(isset($_POST['submit']))
{
//Post Values
$name=$_POST['name'];
$email=$_POST['email'];
$password=md5($_POST['password']);
$status=0;
$activationcode=md5($email.time()); // Creating activation code

$sql="insert into userregistration(name,email,password,activationcode,status) values(:name,:email,:password,:activationcode,:status)";
$query = $dbh->prepare($sql);
$query->bindParam(':name',$name,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':password',$password,PDO::PARAM_STR);
$query->bindParam(':activationcode',$activationcode,PDO::PARAM_STR);
$query->bindParam(':status',$status,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if($lastInsertId)
{
$to=$email;
$msg= "Thanks for new Registration.";   
$subject="Email verification";
$headers .= "MIME-Version: 1.0"."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From: PHPGurukul | Programing Blog (Demo) <[email protected]>'."\r\n"; //Change this to  your email

$ms.="<html></body><div><div>Dear $name,</div></br></br>";
$ms.="<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://yourdomain.com/email_verification.php?code=$activationcode'>Click Here</a></div> 
</body></html>";
mail($to,$subject,$ms,$headers);
echo "<script>alert('Registration successful, please verify in the registered Email-Id');</script>";
echo "<script>window.location = 'login.php';</script>";;
}
else
{
echo "<script>alert('Something went wrong. Please try again.');</script>";
}
}
?>

E-posta doğrulama kodu (email_verification.php). Doğrulama bağlantısını tıkladıktan sonra email_verification.php adresine yönlendireceksiniz.

<?php
include 'config.php';
if(!empty($_GET['code']) && isset($_GET['code']))
{
$code=$_GET['code'];

$sql = "SELECT * FROM userregistration WHERE activationcode=:code";
$query = $dbh -> prepare($sql);
$query->bindParam(':code',$code,PDO::PARAM_STR);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
  
$st=0;
$sql = "SELECT id FROM userregistration WHERE activationcode=:code and status=:st";
$query = $dbh -> prepare($sql);
$query->bindParam(':code',$code,PDO::PARAM_STR);
$query->bindParam(':st',$st,PDO::PARAM_STR);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
$st=1;
$sql = "UPDATE userregistration SET status=:st WHERE activationcode=:code";
$query = $dbh->prepare($sql);
$query -> bindParam(':code',$code, PDO::PARAM_STR);
$query-> bindParam(':st',$st, PDO::PARAM_STR);
$query -> execute();
}
else
{
$msg ="Your account is already active, no need to activate again";
}
}
else
{
$msg ="Wrong activation code.";
}
}
?>

Başarılı doğrulamadan sonra. Giriş yapabilirsiniz (login.php)
giriş formu

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

<table width="100%"  border="0">
<tr>
<td colspan="2"><font color="#FF0000"><?php echo $_SESSION['action1']; ?><?php echo $_SESSION['action1']="";?></font></td>

</tr>

<tr>
<th height="62" scope="row">Email id </th>
<td width="71%"><input type="email" name="email" id="email" value=""  class="form-control" required /></td>
  </tr>
  <tr>
<th height="62" scope="row">Password </th>

<td width="71%"><input type="password" name="password" id="password" value=""  class="form-control" required /></td>
  </tr>
 <tr>

<th height="62" scope="row"></th>

<td width="71%"><input type="submit" name="login" value="Submit" class="btn-group-sm" /> </td>
  </tr>
</table>
 </form>

Giriş için PHP Kodu. Bu kodu login.php'nin en üstüne koyun.

<?php session_start();
error_reporting(0);
include_once("config.php");
if(isset($_POST['login']))
{
$email=$_POST['email'];
$password=md5($_POST['password']);
$sql ="SELECT  * FROM userregistration WHERE email=:email and password=:password";
$query= $dbh -> prepare($sql);
$query-> bindParam(':email', $email, PDO::PARAM_STR);
$query-> bindParam(':password', $password, PDO::PARAM_STR);
$query-> execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
if($query->rowCount() > 0)
{
//fetching name
foreach ($results as $row) {
		$uname=$row->name;
	}

$_SESSION['login']=$email;
$_SESSION['id']=$num['id'];
$_SESSION['name']=$uname;
echo "<script > document.location = 'welcome.php'; </script>";
} else{
echo "<script>alert('Invalid Details');</script>";
}
}
?>

Başarılı bir giriş yaptıktan sonra, welcome.php sayfasına yönlendirileceksiniz.

<?php
session_start();
include_once("config.php");
if($_SESSION['login'])
{
 ?>
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title>PHPGURUKUL | PHP Email Verification Script </title>
		<meta name="generator" content="Bootply" />
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link href="css/bootstrap.min.css" rel="stylesheet">
		<!--[if lt IE 9]>
			<script src="//html5shim.googlecode.com/svn/trunk/html5.js"></script>
		<![endif]-->
		<link href="css/styles.css" rel="stylesheet">
	</head>
	<body>
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
	<div class="navbar-header">
        <a class="navbar-brand" rel="home" href="http://www.phpgurukul.com/">Home</a>
		<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
		<span class="sr-only">Toggle navigation</span>
		<span class="icon-bar"></span>
		<span class="icon-bar"></span>
		<span class="icon-bar"></span>
		</button>
	</div>
	<div class="collapse navbar-collapse">
		<ul class="nav navbar-nav">
			<li><a href="http://www.phpgurukul.com/all-demos/">All Demos</a></li>
			<li><a href="http://www.phpgurukul.com/category/php-projects/">Free Projects</a></li>
			<li><a href="http://www.phpgurukul.com/contact-us/">Contact</a></li>
			<li class="dropdown">
              <a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorials <b class="caret"></b></a>
              <ul class="dropdown-menu">
                <li><a href="http://www.phpgurukul.com/category/php/">PHP </a></li>
                <li><a href="http://www.phpgurukul.com/category/php-oops-concepts/">PHP OOPs</a></li>
                <li class="divider"></li>
                <li><a href="http://www.phpgurukul.com/category/php-data-object/">PDO</a></li>
                <li class="divider"></li>
                <li><a href="http://www.phpgurukul.com/category/inteview-ques-ans/">Interview QA</a></li>
              </ul>
            </li>
		</ul>	
</div>
</nav>
<div class="container-fluid">
  <div class="col-sm-6">
    <div class="row">
      <div class="col-xs-12">
        <h3>PHP Email Verification Script </h3>
		<hr >
		<form name="insert" action="" method="post">
     <table width="100%"  border="0">
     <tr><th>Welcome :
    <td ><font color="#FF0000"><?php echo $_SESSION['name']; ?></font> ||   <a href="logout.php">Logout</a></td>
  </tr>
  <tr>
    <th height="62" scope="row"> </th>
    <td width="71%"></td>
  </tr>
</table>
 </form>

      </div>
    </div>
    <hr>     
  </div><!--/center-->
</div><!--/container-fluid-->
	<!-- script references -->
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
<?php
} else {
header('location:logout.php');	
}
?>

Çıkış Kodu (logout.php)

<?php
session_start();
$_SESSION['login']=="";
session_unset();
$_SESSION['action1']="You have logged out successfully..!";
?>
<script language="javascript">
document.location="login.php";
</script>

Viagra Fiyatları netflix bedava hesap