PHP Contact Form Module


Download and learn how this simple PHP Contact Form Script was made. Technologies used include PHP OOP, MySQL, Bootstrap and HTML5.

Script Overview

This source code will enable you to add a 'contact form' feature on your website. This source code is a very good starting point if you're trying to build your own 'Contact Form Script' from scratch and add some more complex features later.

This is because the basis of this source code are our step by step and easy to understand tutorial. Specifically this tutorial: PHP, MySQL and OOP CRUD Tutorial – Step by Step Guide!

The system looks simple. But I assure you that when you study the source code, you will learn a lot of useful PHP coding techniques.

Some include: How to send a message to a valid email address from a web form, use of settings for your contact form, collecting and storing customer messages on your own database, admin restrictions and more! You can see the detailed list of features on section 6.0 below.

Is This Code For Me?

The source code in this page is NOT for you if:

  • You are already an expert in PHP & MySQL programming.
  • You have a lot of time to code the listed features of our PHP contact form script
  • You are not that interested in learning PHP & MySQL programming.

But, this SOURCE CODE is FOR YOU if:

  • You want to SAVE a significant amount of development time.
  • You want to develop your own PHP contact form script from scratch.
  • You determined to learn how to make a this web application feature in PHP & MySQL.
  • You need some guidance in learning about this script (I'll personally support you & answer your questions)

But if you are an expert in PHP & MySQL programming and would like to take a look at our code, please do so! We’d love to hear your response and great insights! The comments section below is always open for anyone with questions and suggestions.


Before you download, please make sure you have basic understanding of the following topics.

a. PHP, MySQL and OOP CRUD Tutorial – Step by Step Guide!
b. Apache .htaccess RewriteRule Examples

Once you learned our tutorials above, this source code should be easy to understand.

Output Preview

Below are some screenshots of our script's output. You can click an image to view the larger version of it.

Please note that the following images are just output previews. New features might be added already the time you are reading this.

[espro-slider id=6269]

Database Design

Our database name will be "php_contact_form", and we will have three tables: Messages, Settings and Users.


File Structure

The following folders and files are included in our source code. It will have more meaning if you will see the code inside the folders and files.
β”œβ”€ admin/
β”œβ”€β”€β”€ delete_message.php
β”œβ”€β”€β”€ index.php
β”œβ”€β”€β”€ layout_foot.php
β”œβ”€β”€β”€ layout_head.php
β”œβ”€β”€β”€ login_checker.php
β”œβ”€β”€β”€ navigation.php
β”œβ”€β”€β”€ paging.php
β”œβ”€β”€β”€ read_message.php
β”œβ”€β”€β”€ read_message_template.php
β”œβ”€β”€β”€ search_messages.php
β”œβ”€β”€β”€ settings.php
β”œβ”€ config/
β”œβ”€β”€β”€ core.php
β”œβ”€β”€β”€ database.php
β”œβ”€ dev/
β”œβ”€β”€β”€ php_contact_form.sql
β”œβ”€β”€β”€ readme.txt
β”œβ”€ images/
β”œβ”€ libs/
β”œβ”€β”€β”€ css/
β”œβ”€β”€β”€β”€β”€β”€ bootstrap/
β”œβ”€β”€β”€β”€β”€β”€ font-awesome/
β”œβ”€β”€β”€ js/
β”œβ”€β”€β”€β”€β”€β”€ bootbox.min.js
β”œβ”€β”€β”€β”€β”€β”€ custom-script.js
β”œβ”€β”€β”€β”€β”€β”€ jquery.js
β”œβ”€β”€β”€ php/
β”œβ”€β”€β”€β”€β”€β”€ pw-hashing/
β”œβ”€β”€β”€β”€β”€β”€ utils.php
β”œβ”€ objects/
β”œβ”€β”€β”€ message.php
β”œβ”€β”€β”€ setting.php
β”œβ”€β”€β”€ user.php
β”œβ”€ .htaccess
β”œβ”€ contact.php
β”œβ”€ index.php
β”œβ”€ info.php
β”œβ”€ layout_foot.php
β”œβ”€ layout_head.php
β”œβ”€ login.php
β”œβ”€ logout.php
β”œβ”€ navigation.php

What People Say?

Here's what people feel about our work and source code downloads.

"Wow, I love you guys! The best web programming tutorial I’ve ever seen. So comprehensive, yet easy to follow. I love how you combine all necessary elements in such a neat structure."

"The fact that you’ve put it all together saves so much time and its worth buying the code. Makes me feel good supporting a developer like yourself. Keep up the good work!"

"Thanks for making these awesome tutorials! I bought your source codes. To be honest, it’s very readable code and helps me understand a lot of things and how it’s done in PHP. Thanks for that again."

Features List & Download - PHP Contact Form Script

Learn more techniques when coding with PHP, MySQL and OOPYES
Save your precious time coding and searching about how to do the features below.YES
PHP PDO and Prepared StatementsYES
jQuery enabledYES
Bootstrap enabledYES
Font-awesome enabledYES
Buttons are displayed with appropriate iconsYES
Name fieldYES
Email fieldYES
Subject fieldYES
Message fieldYES
Client side validation (HTML5)YES
Server side validation (PHP)YES
Display contact email from settingsYES
Display contact number from settingsYES
Display contact person from settingsYES
Store customer message to databaseYES
Send message to contact email (email set in the settings)YES
Send confirmation email to customerYES
Sending email can work via localhost using the PhpMailer libraryYES
Uses htmlspecialchars($_SERVER["PHP_SELF"]) for form actionYES
Sanitize each submitted field with htmlspecialchars(), strip_tags() and trim() functionsYES
Require value for each fieldYES
Show an error message under input fields if value is missingYES
Validate email address formatYES
Keep values in the form if there are any errorYES
List messages collected from customers using the contact formYES
Display name, subject, sent and action columnsYES
Unread messages in white row backgroundYES
Read messages in gray row backgroundYES
Pagination of messagesYES
Search messages by name, email, subject and message fieldsYES
Read a messageYES
Delete a messageYES
Setting for contact firstnameYES
Setting for contact lastnameYES
Setting for contact genderYES
Setting for contact emailYES
Setting for contact numberYES
Decide if you'll show contact nameYES
Decide if you'll show emailYES
Decide if you'll show contact numberYES
Login using email and passwordYES
Log out userYES
Hashed password stored in databaseYES
Logged-in user name display on the right side of navigation barYES
Log-out button displayed on drop-down when user name was clickedYES
Messages can be read by logged-in admin.YES
Messages can be deleted by logged-in admin.YES
Free support for 6 months.YES
Free source code updates.YES
[purchase_link id="16101" text="DOWNLOAD SOURCE CODE NOW" style="button" color="green"]

Simple Set Up

By now, you were able to download this (PHP Contact Form Script) source code. Here are the few instructions about how to run it.

1. Copy the extracted files to your localhost or upload it to your webserver.

2. You have to create your database using PhpMyAdmin, name of the database: php_contact_form

3. Import the SQL file called "php_contact_form.sql" located in the "dev" folder.

4. Change line 7 .htaccess file (No changes should be made if you put the files on the root directory of your localhost)


5. Run the login.php file on your browser, use the following user credentials.

Username: [email protected]
Password: ninja12qw!@QW

6. To see the contact form, run contact.php

Related Source Code Modules

You can download the PHP SHOPPING CART SYSTEM by modules. Learn more by clicking any 'View Module' button below.

PHP Login & Registration Module
PHP Shopping Cart Module
PHP Product Catalog Module
PHP Content Management Module
PHP Contact Form Module
PHP PayPal Integration Module

Thank You!

Thank you for reading about this PHP Contact Form Script source code and supporting our projects here at!

If you have any questions, comments or suggestions, please do not hesitate to contact me.
a. Send me an email. My email address is [email protected]
b. Go to and chat me up.

Hi! I'm Mike Dalisay, the co-founder of, a site that helps you build web applications with PHP and JavaScript. Need support? Comment below or contact [email protected]

I'm also passionate about technology and enjoy sharing my experience and learnings online. Connect with me on LinkedIn, Twitter, Facebook, and Instagram.