Email subscription concept using php and mysqli - Mostlikers

14 August, 2013

Email subscription concept using php and mysqli

This concept user can register our email id to the particular site. for the purpose of when the site administrator post on any messages or updates its directly send the email on subscribe users. coding function used on when user can be register our email id in website form its post and store to the database.

email subscription img
Create blow type table database connect file using on Mysqli connection through the site

  CREATE TABLE `subscripe` (
     `id` int(11) NOT NULL AUTO_INCREMENT,
     `email` VARCHAR( 25 ) NOT NULL
)



PHP

<?php
if(isset($_POST['submit'])!="")
{
$subscriper=$_POST['user'];
$res1=$conn->query("select * from subscripe where email='$subscriper'");
$search=mysqli_num_rows($res1);
if($search)
{
echo "already subscripe $subscriper this mail";
}
else
{
$res2=$conn->query("insert into subscripe(email) values('$subscriper')");
if($res2)
{
$to = $subscriper;
$from = "mostlikers@gmail.com";
$subject = "Email verfications";
$message= "Hello &nbsp;" .$subscriper." <br/><br/><br/>
Thanks to subscripe on Mostlikers"
;
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
mail($to, $subject, $message, $headers);
echo "thanks to subscripe mostlikers";
}
}
}
?>

HTML

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Email</title>
<style type="text/css">
.login { margin:0 auto; border:dashed 1px #000; width:500px; }
.login form { width:300px; margin:0 auto; }
</style>
</head>
<?php
$conn=new mysqli('localhost','root','','login');
?>
<body>
<div class="login">
<form method="post">
<label>Enter your Email ID</label>
<input type="email" name="user" placeholder="Enter your Email" autocomplete="on" required="required" >
<p align="center">
<input type="submit" value="Submit" name="submit" class="submit" id="submit"></p>
</form>
</div>
</body>
</html>


Live demo

basically email subscription concept based on feed burner so i provide live demo on my site email subscription. just subscribe here and check the mail.
    

4 comments:

  1. never trust user input, escape the email address, currently this code is a serious security flaw!!1

    ReplyDelete
  2. Hi, brother karthick,
    I like this tutorial, but can you post a tutorial in which, user cant download file if they are not subscribed user of site

    I mean i want to give downloadable file to user after they subscribe

    give files to user after succesful subscription

    Can you please publish a tutorial about it

    It will really helpful to increse subscribers...
    Thanks ...

    ReplyDelete
    Replies
    1. Thank you for your comment, sure i will post

      Delete