PHP Projects

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

Contact form with mail function and Storing in the database project has two module :

  1. User Module
  2. 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
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
ALTER TABLE `tblcontactdata`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1;

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="Example@mail.com" 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">
</form>

MYSql database connection

<?php
// DB credentials.
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASS','');
define('DB_NAME','contactdb');
// Establish database connection.
try
{
$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

include('config.php');
if(isset($_POST['submit']))
{
// getting Post values
$name=$_POST['name'];
$phoneno=$_POST['phonenumber'];
$email=$_POST['emailaddres'];
$subject=$_POST['subject'];
$message=$_POST['message'];
$uip = $_SERVER ['REMOTE_ADDR'];
$isread=0;
// 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
$query->bindParam(':fname',$name,PDO::PARAM_STR);
$query->bindParam(':phone',$phoneno,PDO::PARAM_STR);
$query->bindParam(':email',$email,PDO::PARAM_STR);
$query->bindParam(':subject',$subject,PDO::PARAM_STR);
$query->bindParam(':message',$message,PDO::PARAM_STR);
$query->bindParam(':uip',$uip,PDO::PARAM_STR);
$query->bindParam(':isread',$isread,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $dbh->lastInsertId();
if($lastInsertId)
{
//mail function for sending mail
$to=$email;
$headers .= "MIME-Version: 1.0"."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From:PHPGurukul Contact Form Demo<info@phpgurukul.com>'."\r\n";
$ms.="<html></body><div>
<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>";
mail($to,$subject,$ms,$headers);
echo "<script>alert('Your info submitted successfully.');</script>";
}
else
{
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 particular contact
  • Notification feature(Admin can get 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
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

Recommended Tutorials for you


Related posts

User Registration & Login and User Management System With admin panel

Anuj Kumar

Online Library Management System

Anuj Kumar

Directory Management System Using PHP and MySQL

Anuj Kumar

Student Record System In php

Anuj Kumar

Insurance Management System using PHP and MySQL

Sarita Pandey

Shopping Portal ProVersion

Anuj Kumar

Small CRM in PHP

Anuj Kumar

Hospital Management System In PHP

Anuj Kumar

Job Portal Project

Anuj Kumar

28 comments

ink February 7, 2019 at 4:44 pm

How to change colour of the bg !,where to change the code to change the BG colour etc . And how to send mail from database

Reply
Anuj Kumar February 7, 2019 at 5:11 pm

You can change in CSS file.

Reply
ink February 7, 2019 at 4:43 pm

How to change colour of the bg !,where to change the code to change the BG colour etc

Reply
ink February 7, 2019 at 4:39 pm

Sir MIME Service is not working, mail is not getting sent . data are getting stored in db but not going to email, i have changed the email to my personal one in admin side page.

Reply
Anuj Kumar February 7, 2019 at 5:12 pm

Mail function will not work on localhost.

Reply
ink February 11, 2019 at 4:31 pm

How to send email through localhost ? is there a way to do that

Reply
Anuj Kumar February 11, 2019 at 4:42 pm

Use SMTP

Reply
max January 13, 2019 at 9:22 am

Dear, I am unable to get a login at the admin page, There might be an Error.
i have checked and verified everything like a sql database, config file etc… but the problem is going to be same…

Reply
Anuj Kumar January 13, 2019 at 9:31 am

Username is admin and password is Test@123

Reply
yilkal December 15, 2018 at 9:14 pm

it is good so continoues!!!!!

Reply
Rocking pari December 1, 2018 at 2:50 pm

Sir can you please suggest me some mega project topics for final year cse project which r use full in daily life. Please I really need your help.

Reply
Anuj Kumar December 2, 2018 at 7:15 am

online banking project

Reply
https://bolalive.tv November 10, 2018 at 5:13 am

I blog frequently and I truly thank you for your content.
This great article has really peaked my interest.
I’m going to book mark your site and keep checking for new
details about once per week. I subscribed to your Feed too.

Reply
https://bolalive.tv September 25, 2018 at 5:09 am

I blog frequently and I truly thank you for your content.
This great article has really peaked my interest.
I’m going to book mark your site and keep checking for new
details about once per week. I subscribed to your Feed too.

Reply
Chandana August 27, 2018 at 3:28 pm

Sir,Please send me the report of contact form with mail function

Reply
Anuj kumar August 28, 2018 at 3:00 pm

Right now not available

Reply
Adeel Ahmed September 4, 2018 at 5:28 pm

bhai jaan.. Student Result Management Ka admin login nai ho raha..
please password btayain..
jo likha hua waha wo nai lagta

Reply
Anuj kumar September 5, 2018 at 4:57 pm

For Admin Panel
Open Your browser put inside browser “http://localhost/srms”
Login Details for admin : admin/Test@123

Reply
Chandana November 10, 2018 at 5:13 am

Sir,Please send me the report of contact form with mail function

Reply
Anuj kumar November 10, 2018 at 5:13 am

Right now not available

Reply
Adeel Ahmed November 10, 2018 at 5:16 am

bhai jaan.. Student Result Management Ka admin login nai ho raha..
please password btayain..
jo likha hua waha wo nai lagta

Reply
Anuj kumar November 10, 2018 at 5:30 am

For Admin Panel
Open Your browser put inside browser “http://localhost/srms”
Login Details for admin : admin/Test@123

Reply
Shafi August 26, 2018 at 4:07 am

Error on importing the database, unknown character set utf8mp4….i looked into phpmyadmin only utf8 characterset is there……..other thing as you told email service won’t work on localhost, so where to run this ?? Kindly reply.

Reply
Anuj kumar August 26, 2018 at 12:24 pm

Your database not supporting character set utf8. Update your xampp or wamp.

Reply
Shafi November 10, 2018 at 5:13 am

Error on importing the database, unknown character set utf8mp4….i looked into phpmyadmin only utf8 characterset is there……..other thing as you told email service won’t work on localhost, so where to run this ?? Kindly reply.

Reply
Anuj kumar November 10, 2018 at 5:16 am

Your database not supporting character set utf8. Update your xampp or wamp.

Reply
Classgist August 24, 2018 at 7:49 pm

Thumbs. Simple and easy to understand

Reply
Classgist November 10, 2018 at 5:13 am

Thumbs. Simple and easy to understand

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

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