PHP Contact Form Module

Last updated on December 3, 2021 by Mike Dalisay
simple-php-contact-form-script

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.

Pre-Requisite

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.

database-design-php-contact-form-script

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

FEATUREPHP 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
CONTACT FORM
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
FORM SECURITY
Uses htmlspecialchars($_SERVER[“PHP_SELF”]) for form actionYES
Made sure $_SERVER[“REQUEST_METHOD”]==”POST”YES
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
MESSAGES
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
SETTINGS
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
USER
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
SUPPORT AND UPDATES
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)

RewriteBase /YOUR_ROOT_DIRECTORY/

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

Username: [email protected]
Password: [email protected]

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.


ModulesAction
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 codeofaninja.com!

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 https://fb.com/codeofaninja and chat me up.

Published
Categorized as PHP

By Mike Dalisay

Hi, I'm Mike Dalisay, a coder and startup founder. Thank you for visiting codeofaninja.com! I'm also passionate about technology and enjoy sharing my experience and learnings online. Connect with me on Twitter, LinkedIn, Facebook, and Instagram.

Back to top