Wishapp Directory

Project: in this project we will learn how to make website for auto mail send to our reciepent for wishing or greeting them on their birthday date.

The wishing email will be sent automatically on the date of birthday of reciepient. Also will show the button send email who`s birth date will match with current date (you can click on to send email to clients). In this project we will learn about add record, update record, auto send script. Project directory to understand how the subfolder created. It will be using phpmailer library, we have to downalod phpmailer from github repository . To be sent email automatically we have to configure cron job which is in our host dirctory there will be a cron job time configuration to set time to execute or run php script automatically on that day & time. Add Cron Job Command one of them which work on your cron job in CPanel.
/usr/bin/php -f /yourCpanelUsername/public_html/DomainPath/autosend.php 1>> /dev/null 2
/usr/bin/php/home/yourCpanelUsername/public_html/DomainPath/autosend.php >/dev/null
/usr/local/bin/php -q /home/yourCpanelUsername/public_html/DomainPath/autosend.php
/usr/local/bin/php -q /home/yourCpanelUsername/public_html/DomainPath/autosend.php >/dev/null
/usr/local/bin/php/home/yourCpanelUsername/public_html/autosend.php
autosend.php is my php script in which It has written the logic to send email.
PHP
PHP
PHP
PHP

index.php

wishapp/index.php
index.php
              
                <?php include("common/top.php"); ?>
                  <body>
                      <div class="container-fluid" style="margin-top: 50px;">
                        <?php include("common/navbar.php"); ?>
                      <!-- jumbotron -->
                      <center><h2 class="btn-primary  text-white form-control" style="height: 50px; font-size: 25px;">Home</h2></center>
                      <div class="jumbotron">
                        <center><h1 class="text-primary" style="margin-top: -45px;">AutoEmail Sender</h1></center>
                      <center>
                          <div class="row">
                            <!-- <div class="col-md-6"><img src="pics/email.png"  width="400px"></div> -->
                            <div class="col-md-12"><img src="pics/mail.png" align="center" width="340px"></div>
                          </div>
                          </center>
                        <center><p>We welcome you to send E-mail on birthday to our clients to greet them</p></center>
                        <center>
                        <a href="add-form.php" class="btn btn-primary" >Add to send E-mail</a>
                        <a href="login-form.php" class="btn btn-primary" >Add to send E-mail</a>
                      </center>
                    </div>   
                  <?php include("common/footer.php"); ?>
              
            

database

Database table
                
                    CREATE TABLE `users` (
                      `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
                      `name` varchar(100) NOT NULL,
                      `dob` varchar(100) NOT NULL,
                      `email` varchar(100) NOT NULL,
                      `mobile` varchar(50) NOT NULL,
                      `create_at` date NOT NULL
                    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
              
            
wishapp/databases/config.php
config.php
              
                define("DBHOST","localhost");
                define("DBUSER", "root");
                define("DBPASS","");
                define("DBNAME","wishapp"); 
              
            
wishapp/databases/dbcon.php
dbcon.php
              
                <?php  require_once('config.php');
                  $dbcon = mysqli_connect(DBHOST,DBUSER,DBPASS,DBNAME);
                  if($dbcon){
                    return $dbcon;
                  }else {
                    die('Connection  failed'.mysqli_connect_error());
                    exit();
                  }
              
            

add-form.php

wishapp/add-form.php
add-form.php
              
              <?php  
                require_once('database/dbcon.php');
                require_once('add.php');
              ?>
              <?php include("common/top.php"); ?>
              <body style="padding: 5px;">
                  <br>
                    <div class="container w-50" style="margin-top: 30px">
                        <?php include("common/navbar.php"); ?> 
                        <center><?php echo $error; ?><?php echo $msg; ?>  </center>
                        <center><h1 class="bg-primary text-white form-control" style="height: 45px; font-size: 25px;">Submit Details</h1></center>
                          <form action="" method="POST" enctype="multipart/form-data">
                              <div class="form-group">
                                <label for="name"><b>Name:</b></label>
                                <input type="text" class="form-control" name="name" id="name">
                              </div>
                              <div class="form-group birthdate">
                                <label for="dob"><b>Date of Birth:</b></label>
                                <input type="date" class="form-control" name="dob" id="dob">
                              </div>
                              <div class="form-group">
                                <label for="email"><b>E-mail:</b></label>
                                <input type="text" class="form-control" name="email" id="email">
                              </div>
                              <div class="form-group">
                                <label for="mobile"><b>Mobile No:</b></label>
                                <input type="text" class="form-control" name="mobile" id="mobile">
                              </div>
                                <input type="submit" name="submit" value="Submit" class="btn btn-success btn-sm">
                                <button class="btn btn-info btn-sm float-right"><a href="dashboard.php" class="text-white">View Record</a></button>            
                          </form>
                      </div>      
                    <?php include("common/footer.php"); ?>
              
            

functions.php

wishapp/functions.php
              
                <?php 
                function email_exists($email ,$dbcon){
                    $query = "SELECT `id` FROM `users` WHERE `email`= '$email'";
                    $run = mysqli_query($dbcon, $query);
                    if(mysqli_num_rows($run) > 0){
                      return true;
                    }else{
                    return false;
                    }
                }
              
            

add.php

wishapp/add.php
              
              <?php require_once("function.php");
              $msg=''; $error=''; 
              if(isset($_POST['submit'])){
                  $name = mysqli_real_escape_string($dbcon,ucfirst($_POST['name']));
                  $email = mysqli_real_escape_string($dbcon,strtolower($_POST['email']));
                  $dob = mysqli_real_escape_string($dbcon,strtolower($_POST['dob']));
                  $mobile = mysqli_real_escape_string($dbcon,strtolower($_POST['mobile']));

                  if(empty($name)){
                      $error =" <div class='alert alert-danger'> <span style='color:red;'>Please enter your name !! </span> </div>";     
                  }else if(strlen($name)  < 3){
                      $error =" <div class='alert alert-danger'> <span style='color:red;'>The name must contain atleast 3 characters !! </span> </div>";
                  }elseif(empty($email)){
                      $error =" <div class='alert alert-danger'> <span style='color:red;'>Please enter  email address !! </span> </div>";  
                  }else if(!filter_var($email,FILTER_VALIDATE_EMAIL)) {
                      $error =" <div class='alert alert-danger'> <span style='color:red;'>Please enter valid email address !! </span> </div>";   
                  }else if (email_exists($email,$dbcon)){
                      $error =" <div class='alert alert-danger'> <span style='color:red;'>Email already exists !! </span> </div>";
                  }else if(empty($dob)) {
                      $error =" <div class='alert alert-danger'> <span style='color:red;'>Please Enter Date of Birth !! </span> </div>";
                  }else if(empty($mobile)) {
                      $error =" <div class='alert alert-danger'> <span style='color:red;'>Please Enter Mobile Number !! </span> </div>";
                  }else{
                    $query = "INSERT INTO `users`(`name`,`dob`,`email`,`mobile`) VALUES('$name','$dob','$email','$mobile')";
                    $result = mysqli_query($dbcon,$query);
                    if($result){
                        $error =" <div class='alert alert-success'>{$name} has been added successfully </div>";
                          $name='';  $email=''; $dob=''; $mobile=''; 
                    }   
                  }
              }
              ?>
              
            

autosend.php

wishapp/autosend.php
              
                <?php require_once('database/dbcon.php'); ?>
                <?php require 'phpmailer/PHPMailerAutoload.php'; ?>
                <link rel="stylesheet" href="css/bootstrap.min.css">
                    <?php
                      date_default_timezone_set("Asia/kolkata");
                      //Current Date
                      $current_date = date('m-d');
                      //echo "Current date :".$current_date;
                      $query = "SELECT * FROM `users`";
                      $run = mysqli_query($dbcon,$query);
                      while ($row = mysqli_fetch_array($run)){
                          //Date of Birth
                          $db_dob = $row['dob'];
                          $birth_date = strtotime($db_dob);
                          $date_of_birth = date('m-d', $birth_date);
                          $db_name = $row['name'];
                          $db_email = $row['email'];
                        if($date_of_birth == $current_date){
                          // Instantiation and passing `true` enables exceptions
                          $mail = new PHPMailer();
                          //Server settings
                          //$mail->SMTPDebug = 4;                                                        
                          $mail->isSMTP();                      
                          $mail->Host = 'smtp.mailtrap.io';   
                          $mail->SMTPAuth = true;               
                          $mail->Username = 'xxxxxxxxxxx';   
                          $mail->Password = 'xxxxxxxxxxx';  
                          // $mail->SMTPSecure = 'ssl';          
                          $mail->SMTPSecure = 'tls';          
                          $mail->Port = 465;                              
                          $mail->setFrom('senderemail@demo.com', 'Saten Chauhan');
                          $mail->addAddress($db_email, $db_name);     
                          //$mail->addAddress('cc@example.com');              
                          $mail->addReplyTo('nonreply@oursystem', 'Our System');
                          //$mail->addCC('cc@example.com');
                          //$mail->addBCC('bcc@example.com');
                          //$mail->addAttachment('/var/tmp/file.tar.gz');    
                          //$mail->addAttachment(dirname(__FILE__) .'/birth.jpg','pics');    
                          $mail->isHTML(true);                               
                          $mail->Subject = 'Greeting from Smart Infotechsys';
                          $mail->Body    = " <h3>Hello Mr " .$db_name." </h3> <p>We wish you very happy birthday </p> <br> <img src='cid:birth' /> <br> <p> Best Regards  <br> Our Team  <br> Saten Chauhan  </p> ";
                          $mail->addEmbeddedImage('pics/birth.jpg','birth');
                          if(!$mail->send()) {
                              echo " <div class='alert alert-danger'> <span style='color:red;'>Message could not be sent.  </span> </div>";
                              echo 'Mailer Error: '. $mail->ErrorInfo;
                          } else {
                            // header("Refresh: 5; url=dashboard.php");
                              echo " <br> <br> <center> <div class='alert alert-success w-50'> <span style='color:green;'>The message has been sent to {$db_name} for  birth day greeting.  </span> </div> </center>";
                          }
                        }else{
                          $error= "";
                        // echo " <div class='alert alert-danger'><span style='color:red;'>The user`s date of birth does not match today ??.</span></div>";
                      }
                  }
              
            

dashboard.php

wishapp/dashboard.php
dashboard.php
              
                <?php  require_once('database/dbcon.php');
                require_once("add.php");
                $error=''; $msg='';
                  if(isset($_GET['del_id'])){
                      $del_id = $_GET['del_id'];
                      $sql = "SELECT * FROM `users` WHERE `id`='$del_id'";
                      $run = mysqli_query($dbcon,$sql);
                      $data= mysqli_fetch_array($run);
                      echo $name=$data['name'];
                      $qry = "DELETE FROM `users` WHERE `id`='$del_id'";
                      $result = mysqli_query($dbcon,$qry);
                        if($result == 1){
                          header("Refresh: 3; url=dashboard.php");
                          $msg ="<div class='alert alert-success'><span style='color:green'>{$name} has been deleted successfully</span></div>";
                        }else{
                          $error ="<div class='alert alert-success'><span style='color:green'>User has not  been deleted </span></div>";
                      }
                  }
                ?>
                <!-- This part to send email -->
                <?php require 'phpmailer/PHPMailerAutoload.php'; 
                    date_default_timezone_set("Asia/kolkata");
                    $failed=''; $success='';
                    if(isset($_GET['send_id'])){
                        $send_id = $_GET['send_id'];
                          //Current Date
                        $current_date = date('m-d');
                        //echo "Current date :".$current_date;
                        $query = "SELECT * FROM `users`WHERE `id`='$send_id'";
                        $run = mysqli_query($dbcon,$query);
                        if(mysqli_num_rows($run)>0){
                            $row = mysqli_fetch_array($run);
                            //Date of Birth
                            $birth_date = strtotime($row['dob']);
                            $dob = date('m-d', $birth_date);
                            $db_name = $row['name'];
                            $db_email = $row['email'];
                            if($dob == $current_date){
                                //Instantiation and passing `true` enables exceptions
                                $mail = new PHPMailer();
                                //Server settings
                                //$mail->SMTPDebug = 4;                                                        
                                $mail->isSMTP();                      
                                $mail->Host = 'smtp.mailtrap.io';   
                                $mail->SMTPAuth = true;               
                                $mail->Username = '80407410675335';   
                                $mail->Password = '0668c6f4267147';  
                                // $mail->SMTPSecure = 'ssl';          
                                $mail->SMTPSecure = 'tls';          
                                $mail->Port = 465;                                  
                                $mail->setFrom('satenchauhan@gmail.com', 'Saten Chauhan');
                                $mail->addAddress($db_email, $db_name);     
                                //$mail->addAddress('cc@example.com');              
                                $mail->addReplyTo('nonreply@oursystem', 'Our System');
                                //$mail->addCC('cc@example.com');
                                //$mail->addBCC('bcc@example.com');
                                //$mail->addAttachment('/var/tmp/file.tar.gz');    
                                //$mail->addAttachment(dirname(__FILE__) .'/birth.jpg','pics');    
                                $mail->isHTML(true);                               
                                $mail->Subject = 'Greeting from Saten Chauhan';
                                $mail->Body    = "<h3>Hello Mr  <h4>" .$db_name."</h4></h3><p>We wish you very happy birthday</p><br><img src='cid:birth' /><br><p> Best Regards <br> Our Team <br> Smart Infotechsys </p> ";
                                $mail->addEmbeddedImage('pics/birth.jpg','birth');
                                  if(!$mail->send()) {
                                      $failed= "<div class='alert alert-danger'><span style='color:red;'>Message could not be sent. </span></div>";
                                      $failed= 'Mailer Error: ' . $mail->ErrorInfo;
                                  } else {
                                      header("Refresh: 3; url=dashboard.php");
                                      $success = "<div class='alert alert-success'><span style='color:green;'>The message has been sent to {$db_name} for greeting birth day. </span></div>";
                                  }
                                }else{
                                  return 0;
                              }
                          }else{
                              $failed= "<div class='alert alert-danger'><span style='color:red;'>No user`s records found  ??.</span></div>";
                          }
                      }
                ?>
                <?php include("common/top.php"); ?>
                <body style="padding: 5px;">
                    <?php include("common/navbar.php"); ?><br>
                      <div class="container-fluid w-100 pt-5">
                        <div class="row">
                          <div class="col-lg-10 offset-lg-1">
                          <?= $error; ?> <?= $msg; ?>
                          <button class="btn btn-success float-left"><a href="add-form.php" class="text-white"> +Add Record</a></button>
                          <h2 class="bg-primary text-white text-center">Users Records</h2>
                          <table class="table table-bordered stripped p-5">
                            <thead class="bg-secondary text-white">
                                <tr>
                                <th>Sr.#</th>
                                <th>Name</th>
                                <th>Date of Birth</th>
                                <th>E-mail Address</th>
                                <th>Mobile No</th>
                                <th colspan="3" width="15%" class="text-center">Action</th>
                                </tr>
                            </thead>
                            <tbody>
                              <?php
                                //Current Date
                                $current_date = date('m-d');
                                // echo "Current date :".$current_date;
                                $sql = "SELECT * FROM `users`";
                                $result = mysqli_query($dbcon,$sql);
                                if(mysqli_num_rows($result) > 0):
                                  
                                  while($row = mysqli_fetch_assoc($result)):?>  
                                  <?php 
                                //Date of Birth
                                  $birth_date = strtotime( $row['dob']);
                                  $dob= date('m-d', $birth_date);
                                //echo "birth_date ".$dob; ?>   
                              <tr>
                                <td><?= $row['id']; ?></td>
                                <td><?= $row['name']; ?></td>
                                <td><?= $row['dob']; ?></td>
                                <td><?= $row['email']; ?></td>
                                <td><?= $row['mobile']; ?></td>
                                <?php if($current_date == $dob) :?>  
                                    <td><a href="dashboard.php?send_id=<?= $row['id']; ?>" class="btn btn-success btn-sm text-white">Send Email</a> </td>
                                <?php else  :?>  
                                  <td><button class="btn btn-warning btn-sm text-dark">Not Today</button></td>
                                <?php endif; ?>   
                                <td><a href="update-form.php?edit_id=<?= $row['id']; ?>" class="btn btn-info btn-sm text-white">Edit</a> </td>
                                <td><a href="dashboard.php?del_id=<?= $row['id']; ?>" class="btn btn-danger btn-sm text-white">Delete</a></td>
                              </tr>
                                <?php endwhile; ?>
                              <?php endif; ?> 
                            </tbody>
                            </table>
                              <button class="btn btn-primary btn-sm float-left"><a href="add-form.php"  class="text-white"> +Add Record</a></button> 
                              <button class="btn btn-danger btn-sm"><a href="index.php" class="text-white">Cancel</a></button><br><br>
                              <?php echo  $failed; ?> <?php  echo  $success; ?>
                            </div><br>
                        </div>
                      </div>      
                <?php include("common/footer.php"); ?>
              
            

update-form.php

To update client/customer's data (Process and update form on same file).

wishapp/update-form.php
update-form.php
              
                <?php 
                // Update Data Process===============================================
                session_start();
                require_once('database/dbcon.php');
                $msg='';$error='';
                  if(isset($_GET['edit_id'])){
                      $edit_id = $_GET['edit_id'];
                      $qry = "SELECT * FROM `users` WHERE `id`='$edit_id'";
                      $result = mysqli_query($dbcon,$qry);
                      if(mysqli_num_rows($result) > 0){
                          $row = mysqli_fetch_assoc($result);
                          $edit_name = $row['name'];
                          $edit_email = $row['email'];
                          $edit_dob = $row['dob'];
                          $edit_mobile = $row['mobile'];
                      }else{
                      return 0;
                      }       
                  }
                  if(isset($_POST['update'])){
                      $name = mysqli_real_escape_string($dbcon,ucwords($_POST['name']));
                      $dob = $_POST['dob'];
                      $email = mysqli_real_escape_string($dbcon,strtolower($_POST['email']));
                      $mobile = $_POST['mobile'];
                      $update_query = "UPDATE `users` SET `name`='$name', `dob`='$dob', `email`='$email', `mobile`='$mobile' WHERE id=$edit_id";
                      if(mysqli_query($dbcon,$update_query)){
                        header("Refresh:3; url=dashboard.php");
                        $msg = "<div class='alert alert-success w-100' style='color:green;'>User record has been updated !</div>";
                      }else{
                        $error = "<div class='alert alert-danger w-100' style='color:red;'>User has not been updated !</div>";
                      }  
                  }
                ?>
                <!-- Update Form==================================================================== -->
                <?php include("common/top.php"); ?>
                <body style="padding: 5px;">
                    <br><br><br>
                      <div class="container w-50" style="margin-top: 30px">
                          <?php include("common/navbar.php"); ?>
                          <center><?php echo $msg; ?><?php echo $error; ?></center>
                                 
                          <center><h1 class="bg-primary text-white form-control" style="height: 45px; font-size: 25px;">Update Details</h1></center>
                          <form action="#" method="POST">
                              <div class="form-group">
                                <label for="nname"><b>Name:</b></label>
                                <input type="text" id="name" class="form-control" name="name" value="<?= $edit_name; ?>"   placeholder="Enter Your Name">
                              </div>
                            <div class="form-group birthdate">
                                <label for="dob"><b>Date of Birth:</b></label>
                                <input type="date" id="dob-id" class="form-control" name="dob" value="<?= $edit_dob; ?>"  placeholder="Enter Date of Birth">
                              </div>
                              <div class="form-group">
                                <label for="email"><b>E-mail:</b></label>
                                <input type="text" id="email" class="form-control" name="email" value="<?= $edit_email; ?>"  placeholder="Enter E-mail Address">
                              </div>
                              <div class="form-group birthdate">
                                <label for="mobile"><b>Mobile:</b></label>
                                <input type="text" id="mobile" class="form-control" name="mobile" value="<?= $edit_mobile; ?>"  placeholder="Enter Date of Birth">
                              </div>
                              <center><input type="submit" name="update" value="Update" class="btn btn-primary">
                              <a href="display.php" class="btn btn-danger">Cancel</a>
                              </center>             
                          </form>
                        </div>  
                <?php include("common/footer.php"); ?>
              
            


PHPMailer folder

myproject/phpmailer

To send mail for forgotten password using phpmailer.

All important file and classes in phpmailer folder.

PHPMailer make easy to handle emailing process.

To download PHPMailer library click on link below.

Download PHPMailer

css and js folder

You must download and include bootstrap css and javascript source files for good interface OR You can add cdn link from bootstrap website.
myproject/css
bootstrap.min.css
myproject/js
bootstrap.min.css
jquery.min.css