PHP Contact Form

PHP Contact Form

A contact form is an essential tool in converting a user into a customer. In this article, you will get a free PHP contact form script that can be used on your website. It is responsive and will work seamlessly on mobile, tablet and other devices.

The contact form initiates a cold conversation with your user and who may become a client in the future. The importance of the best contact form on a website is almost always undermined. Building a PHP contact form is easy but building it right is difficult.

Читайте также:  Php call to undefined function each

In this tutorial, we are having a PHP contact form to let the user send their queries, clarifications, feedback and more details. In this contact form example, there are two PHP files handling the submitted form fields in two different ways.

In the index.php script, the posted contact form data are stored in the database. In the send_contact_mail.php file, I have created PHP code to send an email containing the submitted contact information.

This screenshot shows the output of the PHP contact form template. On this form submission, the form fields are validated and the validation response messages are displayed next to the form field label. After successful PHP processing on the contact form data, the success message will be shown at the bottom of this form template.

PHP-Contact-Form-Output

Contact Form User Interface

The PHP contact form UI with the Name, Email, Subject and Content fields can be shown to the user by using this HTML script. If you are looking for a responsive contact form UI, check the article.

In this HTML code, the UI is kept as simple as possible as the focus is on demonstrating the functionality of sending an email or storing the information in the database.

It includes a jQuery form validation script to return the validation directive with the boolean value. If the validation function returns true, then the form will be submitted to the PHP. Otherwise, the corresponding validation messages are shown in the form to let the user what is wrong with the form data they have submitted.

     




?>
function validateContactForm() < var valid = true; $(".info").html(""); $(".input-field").css('border', '#e0dfdf 1px solid'); var userName = $("#userName").val(); var userEmail = $("#userEmail").val(); var subject = $("#subject").val(); var content = $("#content").val(); if (userName == "") < $("#userName-info").html("Required."); $("#userName").css('border', '#e66262 1px solid'); valid = false; >if (userEmail == "") < $("#userEmail-info").html("Required."); $("#userEmail").css('border', '#e66262 1px solid'); valid = false; >if (!userEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-])?$/)) < $("#userEmail-info").html("Invalid Email Address."); $("#userEmail").css('border', '#e66262 1px solid'); valid = false; >if (subject == "") < $("#subject-info").html("Required."); $("#subject").css('border', '#e66262 1px solid'); valid = false; >if (content == "") < $("#userMessage-info").html("Required."); $("#content").css('border', '#e66262 1px solid'); valid = false; >return valid; > 

PHP Contact Form Input Processing

In the contact form template, the form tag is specified with the request method POST. On successful form submission after jQuery validation, the PHP script accesses the form data by using $_POST request method.

A contact form always faces spam issues. There are numerous autonomous bots that scan the web regularly looking for forms and in particular contact forms to submit spam information.

In the spam content, there will be mostly links to legitimate sites trying to promote them. There are two ways to block those spams, one by custom script implementing honeypot and related logic, and second by using captcha implementation like Google reCaptcha.

If you are looking to implement the captcha yourself, check the PHP contact form with the Google reCAPTCHA article.

The index.php and send_contact_mail.php PHP files are used to handle the PHP contact form data to store in the database and to send via email, respectively. Both of these PHP files use the same contact form template created with the contact-view.php file.

Send Contact Form Input Data via an Email

In this PHP code, the contact form data are received by using $_POST PHP superglobal. Those data are used to set the mail header and body and set with the PHP mail function.

Once the email is sent to the recipient then the success message is shown in the contact form UI to acknowledge the user. You can send email using the PHPMailer package and refer to send email in PHP using the Gmail SMTP server.

 if (! empty($_POST["send"])) < $name = $_POST["userName"]; $email = $_POST["userEmail"]; $subject = $_POST["subject"]; $content = $_POST["content"]; $toEmail = "admin@phppot_samples.com"; // CRLF Injection attack protection $name = strip_crlf($name); $email = strip_crlf($email); if (! filter_var($email, FILTER_VALIDATE_EMAIL)) < echo "The email address is invalid."; >else < // appending \r\n at the end of mailheaders for end $mailHeaders = "From: " . $name . "\r\n"; if (mail($toEmail, $subject, $content, $mailHeaders)) < $message = "Your contact information is received successfully."; $type = "success"; >> > require_once "contact-view.php"; ?> 

Store Contact Form data in the Database

This PHP code helps you to store the PHP contact form data in the database. Create a database table tbl_content with the name, email and more columns corresponding to our contact form fields. After getting the form data in the PHP, they will be used to form the MySQL INSERT statement.

By executing the INSERT statement, the contact form data will be stored in the database. The following code implements the MySQL database connection and accesses the database to insert contact information. After the successful database insert the $message variable is set accordingly.

prepare("INSERT INTO tblcontact (user_name, user_email, subject,content) VALUES (?, ?, ?, ?)"); $stmt->bind_param("ssss", $name, $email, $subject, $content); $stmt->execute(); $message = "Your contact information is saved successfully."; $type = "success"; $stmt->close(); $conn->close(); > require_once "contact-view.php"; ?> 

After executing the above insert query, the contact data will be added to the database table as,

mysql_contact_table

Contact form database table structure

-- -- Database: `contactform_database` -- -- -------------------------------------------------------- -- -- Table structure for table `tblcontact` -- CREATE TABLE `tblcontact` ( `contact_id` int(11) NOT NULL, `user_name` varchar(100) NOT NULL, `user_email` varchar(255) NOT NULL, `subject` varchar(255) NOT NULL, `content` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Indexes for dumped tables -- -- -- Indexes for table `tblcontact` -- ALTER TABLE `tblcontact` ADD PRIMARY KEY (`contact_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `tblcontact` -- ALTER TABLE `tblcontact` MODIFY `contact_id` int(11) NOT NULL AUTO_INCREMENT; 

Источник

28+ Best PHP Contact Form Templates

Every website needs a contact sample form or a responsive ‘email us page’ to let customers and clients ask for a quote and further details about your small business, services, and products. You do not need to add colorful and sophisticated information to impress internet users. It would be best to have a simple yet responsive layout that allows your website visitors to inquire easily.

php contact form templates

We listed the best PHP contact form templates below to help new and existing website designers. You can customize the script of our PHP website templates easily with HTML, Boostrap, Dreamweaver, Ajax, CSS, and on other open source platforms and tools, you are using today.

Responsive PHP Contact Form Layout

contact form

Free Simple Open Source PHP Contact Form

simple php contact form

Easy PHP Contact Form Script

easy php contact form script

PHP Contact Form Create Forms Using HTML & PHP

php contact form create forms using html php

A simple PHP contact simple form can be created using the HTML scripts. They are very simple and easy for the visitors to fill. The contact form has upright details about the visitor like name, email, IT software website, and some text.

Bootstrap Contact Form with PHP

bootstrap contact form with php

Bootstrap is a front-end framework, so we require a PHP script to make a complete bootstrap contact printable form. It has many built-in features. The submit forms, send, save and other options are available.

Simple Contact Form Developed in PHP with HTML5

simple contact form developed in php with html

HTML5 is the fifth and most advanced version of the HTML markup language. This can be used to create contact forms with much detailing and fields. The details in the contact Word form are simple and easy to understand.

Free Easy PHP Contact Form

easy php contact form

The PHP contact forms are very easy to create. It contains the essential fields necessary for the contact form. Contact forms are the basic elements of the internet and technology. The templates for the easy PHP contact forms are available easily.

PHP Contact Form with Validation

php contact form with validation

Contact IT forms are the basic elements for collecting the details of the user or visitor. Validation is necessary to provide services security and authentication of the details and also to protect it from spammers. The details from the working people mostly require validation.

Nice & Simple Contact Form

nice simple contact form

Free Minimal PHP Contact Form

minimal contact form

A contact application form with minimum details and codings is mostly used for collecting the least details like Name and email id or contact no. There are many free download templates for a minimal PHP contact form.

Contact Us Form with Captcha

contact form with captcha

The contact us form with the captcha is required in the field of data entry and job portals. They contain the following details such as the name, email address, and message. Also to validate it a captcha code or image is generated.

Normal Contact Form

normal contact form

ContactPLUS+ – PHP Contact Form

contactplus php contact form

Simplex Ajax Contact Form Pro

dark simplex ajax contact form pro

How to Create Contact Form in Dreamweaver

Dreamweaver is a mail-to contact card form creating tool. It is very simple and easy to use. The website provides a simple tutorial on how to create the contact form. The first step is to collect the email address, then add the email form field and address field, and finally sending option. It is simple as that.

How to Make a PHP Contact Form

  • So the first step is to create a PHP file.
  • The second step is to write the PHP script.
  • You can add more types of data, fields, and boxes within the request form. For more security, you can add CAPTCHA verification and Passwords.

PHP Ajax Quotation Form

php ajax quotation form download

The Ajax quotation forms are the form templates that are ready to use. It can be used in PHP. The Ajax forms are usually well documented. Some of the quotation forms are available for free whereas some require license software purchase.

Dreamweaver Multiple Contact Forms

multiple contact forms

Easy PHP Contact Form Script with Validation

easy php contact form script

There are many contact form layout scripts available. The validation helps in storing the details of the customer safely. Generating a simple validation code is very easy. Here is the best example of it.

Ajax PHP Contact Form

ajax php contact form template

Cool PHP Contact Form

best php contact form template

AJAX Contact Form

sample ajax contact form template

PHP Contact Form to Email US Page and CRM

email crm php contact form

Cross Platform Simple PHP Contact Form

cross platform simple php contact form

The best part about the cross-platform contact evaluation form is its simplicity and it has a ready-to-use script that supports all the forms like PHP, Joomla, etc, it is very adaptable.

Unique PHP Contact Form with HTML and CSS

php contact form with html and css

Awesome PHP Email Contact Form with CSS

awesome php email contact form with css

PHP AJAX Contact Form with Admin CSV

php ajax contact form with admin csv

PHP AJAX contact form is very useful and has much functionality. The admin CSV templates and scripts are available online for free and license purchase. It has many CSV exporters and filters. You may also view Best Ajax PHP Templates.

PHP form generator is the one place where you can create your customized contact form format with much ease and simplicity. To collect the details from the clients is very useful.

A contact form plays an important role when it comes to small businesses in PSD. If you’re a business-runner and most of your customers and business revenue comes from the online space, you must pick an apt contact form template, which helps you know your customers better with the help of the feedback they met out. Although contact forms have been around for a good twenty years with the recent advantages and developments in the interface and security provided to users, the clients can be sure of receiving proper and comprehensive feedback from the users. You may also like Design Website Templates.

Источник

Оцените статью