Email verification is a process to check the user authenticity, whether the person who is trying to access the services is right user or wrong user.

True register users are allowed to use all services provided by the provider and fake users are denied because they are not authorized users to use the specific services.

PHP  Email Verification Script for Downloading e-book is all about to download the e-books after a successful email authentication.

If a user is successfully authenticated in email verification then they get the permission to download the e-book.

This script performs mainly three major task listed below.

  1. Get User Info(User name & email id)
  2. Mail_Verification(Verify user by  Mail account)
  3. File_Download (File_download window)

Watch the live demo or download code from the link given below

PHP Email Verification


 

Our service Mailget can provide you a complete solution


Change Settings in your Gmail account:

For this you can refer to our blog post Send email via Gmail SMTP server in PHP which will give you a clear idea about the settings you need to change in gmail and how you can use PHPMailer Library.

Concept Behind the Script

In Index page user enter his Name, email id and then click submit button.

the User gets an email in his inbox with a message,”Please click the below link(highlighted) for mail verification”, as soon as user click that link he is redirected to download page.

In download page user finds the download link where he can easily download the book by clicking on the download link.

Script Description:-

This script contain two page name ‘index.php’ and ‘download.php’ along with images folder,class(Mail library) and CSS folder.

Index.php

In this script we are going to make a  email verification form where a user is asked to fill the info like user name &  user emailid .

after filling this info he will submit the form and will receive a verification link(highlighted link) in email account , if user click that verification link he is redirected to the download page ,where he can download the book.pdf after clicking the download link.



<?php
include "classes/class.phpmailer.php"; // include the class name

//Generate random hash value
$hash = md5(rand(0, 1000));
if (isset($_POST['id'])) {
$id1 = $_POST['id'];
if ($id1 == $hash) {

header('location:download.php');
}
}

 

if (isset($_POST['dsubmit'])) {

$msg1 = "Download Link has been sent please check your Mail";
echo "<script type='text/javascript'>alert('$msg1')</script>";
}

if (isset($_POST['dsubmit'])) {
$emailid = $_POST['textmail'];
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; // or 587
$mail->IsHTML(true);
$mail->Username = "Insert you gmail id";
$mail->Password = "Insert your gmail password here";
$mail->SetFrom("$emailid");
$mail->Subject = "Your Gmail SMTP Mail";
$mail->Body = "<b>Hi, your are welcome to Formget.com Please click the below link to verify your account <br/><br/>Link:-<a href='http://localhost/php-email-verification/download.php?id={$hash}'>$hash</a></b>";
$mail->AddAddress("$emailid");
if (!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {

}
}

?>

<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PHP Email Verification Script for Downloading ebook</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="main">
<center><h1>PHP Email Verification Script for Downloading ebook</h1></center>
<div id="login">
<h2>Enter your Details Below to receive a Secure Download Link</h2>
<hr>
<div id="left">

<img src="images/book10.jpg" alt=""/>

</div>
<div id="right">
<div id ="form1">
<form method="post" action ="" id="ctform">
<label><b>Your Name :</b></label>
<input type="text" id ="text1" name ="textname" required/>
<br/>
<br/>
<label><b>Your EmailID :</b></label>
<input type="email" name ="textmail" id ="text1" required/>
<br/>
<br/>
<input type="submit" id ="dsubmit" value ="submit" name ="dsubmit" />
</form>
</div>
</div>
</div>
</div>
</body>
</html>

When user runs  this page he gets a optin window asking for

  1. Enter your name
  2. Enter your email id

After entering the valid email id he need to click on submit button , as he click submit button he gets an alert message promoting that “verification link has been sent to your mail”.

Then user needs to login to his email account for verification, as he opens his mail inbox he gets a inbox message and after opening that message he is asked for click one of the “highlighted link” for verifying his mail.

Download.php

After successfull email verification the user is sent to this page where he will receive a thanks message ,user is allowed to download the book.pdf by clicking the download link provided in this page.

<?php
if(isset($_GET['id1']))
{
$filename="phpebook.pdf";
$file="ebook/phpebook.pdf";
$len = filesize($file); // Calculate File Size
ob_clean();
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type:application/pdf"); // Send type of file
$header="Content-Disposition: attachment; filename=$filename;"; // Send File Name
header($header );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$len); // Send File Size
@readfile($file);
exit;
}
//echo"<h2>Thanks for download</h2>";
?>
<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PHP Email Verification Script for Downloading ebook</title>
<link href="css/style.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="main">
<center><h1>PHP Email Verification Script for Downloading ebook</h1></center>
<div id="ebook_download">
<h2>Thanks for verification</h2>
<hr>
<div id="right">
<h3 id="vermsg">Here you can download your file by clicking on <BR>Download link right below.</h3>
<a href="download.php?id1=downlaod"> <img src="images/downbtn.gif" alt="" id="downbtnimg"/></a>.
</div>
</div>
</div>
</body>
</html>

As user click that link he is directly sent to the download page with a message “Thanks for verification please click the below link for downloading the book” ,as he click that  link the downloading process starts, and user gets the appropriate book pdf file.

Style.css

Includes basic styling of HTML elements.


@import url(http://fonts.googleapis.com/css?family=Raleway);
#main{
width:960px;
margin:50px auto;
font-family:raleway;
}
span{
color:red;
}

h2{
background-color: #FEFFED;
text-align:center;
border-radius: 10px 10px 0 0;
margin: -10px -40px;
padding: 15px;
}

hr{
border:0;
border-bottom:1px solid #ccc;
margin: 10px -40px;
margin-bottom: 30px;
}
#login{
height: 500px;
width: 90%;
float: left;
border-radius: 10px;
font-family:raleway;
border: 2px solid #ccc;
padding: 10px 40px 33px;
margin-top: 23px;
}
input[type=text],input[type=email]{
width:99.5%;
padding: 10px;
margin-top: 8px;
border: 1px solid #ccc;
padding-left: 5px;
font-size: 16px;
font-family:raleway;
}
input[type=submit]{
width: 40%;
background-color:#FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 10px;
font-size:20px;
cursor:pointer;
border-radius: 5px;
}
#profile{
padding:50px;
border:1px dashed grey;
font-size:20px;
background-color:#DCE6F7;
}
#left{
// background-color: rgb(254, 255, 237);
width: 415px;
height: 420px;
float: left;
border: 1px dashed rgb(215, 215, 215);
box-shadow: 0px 5px 17px 1px #99A3AD, 0px 0px 40px #EEEEEE;
}
#right{
width: 326px;
float: right;
height: 321px;
/* border: 2px solid red; */
border: 1px dashed rgb(215, 215, 215);
box-shadow: 0px 5px 17px 1px #99A3AD, 0px 0px 40px #EEEEEE;
padding: 50px;
}

#left img {
width: 230px;
height: 289px;
margin-left: -75px;
margin: 65px 15px 10px 94px;
background-repeat: round;
}
#left img:hover{
opacity:.80;
}
#left p{
font-size: 18px;
margin-left: 128px;
}
#right p{
padding: 20px;
}
#paypal_logo{
margin: 10px 315px;
float: right;
}
#results {
width: 100%;
margin-top: 30px;
//border: 1px solid #ccc;
table-layout: auto;
margin-bottom: 30px;
}
table {
border-collapse: collapse;
border-spacing: 0;
}
thead {
display: table-header-group;
vertical-align: middle;
border-color: inherit;
}
.head {
font-size: 15px;
font-family: "proxima_novasemibold", sans-serif;
background: #FEFFED;
color: #1d4c55;
border: 1px solid #ccc;
}
tr {
display: table-row;
vertical-align: inherit;
border-color: inherit;
}
.head th{
//border-right: 1px solid #ccc;
//border-bottom: 1px solid #ccc;
line-height: normal;
padding: 10px 0px;
text-align: left;
padding-left: 3%;
}
td {
//border-right: 1px solid #ccc;
border-bottom: 1px solid #ccc;
line-height: normal;
padding: 10px 0px;
text-align: left;
padding-left:3%;
vertical-align: top;
}
tbody {
display: table-row-group;
vertical-align: middle;
border-color: inherit;
}
tr {
display: table-row;
vertical-align: inherit;
border-color: inherit;
}
#return {
width: 492px;
height: auto;
float: left;
border-radius: 10px;
font-family: raleway;
border: 2px solid #ccc;
padding: 10px 40px 30px;
margin-bottom: 50px;
}
#return h3#success {
text-align: center;
font-size: 24px;
color: green;
margin-bottom: 10px;
}
#return P {
text-align: left;
}
#return .back_btn {
margin-top: 30px;
text-align: center;
}
#btn {
width: 100%;
background-color: #FFBC00;
color: white;
border: 2px solid #FFCB00;
padding: 10px 70px;
font-size: 20px;
cursor: pointer;
border-radius: 5px;
margin-bottom: 15px;
margin: 0 auto;
}
a{
text-decoration:none;
color: #33BADB;
}
.success_main_heading{
margin-left: -40%;

}
#return h3#fail{
text-align: center;
font-size: 24px;
margin-top: 50px;
color: red;
margin-bottom: 10px;
}
.red{
color:red;
font-weight: bold;
}
ul li{
margin-bottom: 15px;
text-align: justify;
margin-right: 20px;
}
hr.style-four {
margin-bottom: 10px;
width: 300px;
padding: 0;
border: none;
border-top: 1px solid rgba(0, 0, 0, 0.1);
color: #333;
text-align: center;
}
hr.style-four:after {
content: "Note";
display: inline-block;
position: relative;
top: -0.7em;
font-size: 1em;
padding: 0 0.25em;
background: white;
font-weight: 600;
}
#vermsg{
font-family: raleway;
color: #BFBFBF;
font-size: 22px;
}
#form1 {
padding-top: 27px;
width: 248px;
margin: 15px auto;
}
#downbtnimg {
margin: 63px 10%;
}
#right h3 {
margin-top: -8px;
text-align: center;
/* padding: 0; */
}
#ebook_download{
height: 500px;
width: 45%;
float: left;
border-radius: 10px;
font-family:raleway;
border: 2px solid #ccc;
padding: 10px 40px 33px;
margin-top: 23px;
margin-left: 22%;
}

Conclusion :

After reading the above post, I am sure you will give a try to the script provided and implement it in your own projects as well. Feel free to visit our website again in the future to get in touch with new coding tricks. You can let us know about your feedback in the space provided below :)