Contact form with mail function and Storing data in the database – Mini Project

  • User Module
  • admin Module
  • User Module

    Sql table structure for tblcontactdata table where we will store our data

    CREATE TABLE `tblcontactdata` (
      `id` int(11) NOT NULL,
      `FullName` varchar(200) DEFAULT NULL,
      `PhoneNumber` char(12) DEFAULT NULL,
      `EmailId` varchar(200) DEFAULT NULL,
      `Subject` varchar(255) DEFAULT NULL,
      `Message` mediumtext,
      `UserIp` varbinary(16) DEFAULT NULL,
      `PostingDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
      `Is_Read` int(1) DEFAULT NULL
    ALTER TABLE `tblcontactdata`

    Now create a HTML for user inputs. index.php

    <form name="ContactForm" method="post">
    <h4>your name</h4>
    <input type="text" name="name" class="user" placeholder="Johne"  autocomplete="off" required>
    <h4>your phone number</h4>
    <input type="text" name="phonenumber" class="phone" placeholder="0900.234.145678" maxlength="10" required autocomplete="off">
    <h4>your email address</h4>
    <input type="email" name="emailaddres" class="email" placeholder="" required autocomplete="off">
    <h4>your subject</h4>
    <input type="text" name="subject" class="email" placeholder="Subject" autocomplete="off">
    <h4>your message</h4>
    <textarea class="mess" name="message" placeholder="Message" required></textarea>
    <input type="submit" value="send your message" name="submit">

    MYSql database connection

    // DB credentials.
    // Establish database connection.
    $dbh = new PDO("mysql:host=".DB_HOST.";dbname=".DB_NAME,DB_USER, DB_PASS,array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));
    catch (PDOException $e)
    exit("Error: " . $e->getMessage());

    Insert Data into Database

    // getting Post values
    $uip = $_SERVER ['REMOTE_ADDR'];
    // Insert quaery
    $sql="INSERT INTO  tblcontactdata(FullName,PhoneNumber,EmailId,Subject,Message,UserIp,Is_Read) VALUES(:fname,:phone,:email,:subject,:message,:uip,:isread)";
    $query = $dbh->prepare($sql);
    // Bind parameters
    $lastInsertId = $dbh->lastInsertId();
    //mail function for sending mail
    $headers .= "MIME-Version: 1.0"."\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
    $headers .= 'From:PHPGurukul Contact Form Demo<>'."\r\n";
    <div><b>Name:</b> $name,</div>
    <div><b>Phone Number:</b> $phoneno,</div>
    <div><b>Email Id:</b> $email,</div>";
    $ms.="<div style='padding-top:8px;'><b>Message : </b>$message</div><div></div></body></html>";
    echo "<script>alert('Your info submitted successfully.');</script>";
    echo "<script>alert('Something went wrong. Please try again');</script>";

    Admin Module

    Admin Panel Features 

    • Secure login with password hashing
    • Admin Dashboard
    • Manage Contact’s
    • Report’s
    • Update Remark on the particular contact
    • Notification feature(Admin can get the notification on every contact)
    • Admin Can update email id where he/she want to receive email.
    • Change Password.
    • Logout.
    In this project admin and user will a get copy of contact form  on email. Email function will not work on localhost .

    How to run Contactform Mini Project

    1. Download the the zip file

    2. Extract the file and copy contactform folder

    3.Paste inside root directory(for xampp xamp/htdocs, for wamp wampp/www,for lamp var/www/html)

    4. Open phpmyadmin (http://localhost/phpmyadmin)

    5. Create a database with name contactdb

    6. Import newsportal.sql file(given inside the zip package in sql file folder)

    7.Run the script http://localhost/contactform (frontend)

    8. For admin panel http://localhost/contactform/admin

    Credential for admin panel :

    username  : admin

    Password : Test @123

    Video Project Demo————

    View Demo

    LIve Project Demo————

    View user Demo View AdminDemo

    Contact form with mail function and Storing data in the database – Mini Project (Full Source Code)
    Size: 19.1 MB
    Version: V 1.0

    Anuj Kumar

    This is Anuj Kumar. I’m a professional web developer with 4+ year experience. I write blogs in my free time. I love to learn new technologies and share with others.
    I founded PHPGurukul in September 2015. The main aim of this website to provide PHP, Jquery, MySQL, PHP Oops and other web development tutorials.

    Recommended Tutorials for you


    This site uses Akismet to reduce spam. Learn how your comment data is processed.

    Follow us

    Don't be shy, get in touch. We love meeting interesting people and making new friends.