PHP/MySQL Contact Form with jQuery

Here’s an implementation of a contact form with PHP and jQuery. Usually, one would only want the message posted by the user to be sent to an email address. This script does that and also saves all these messages in the database for the admin to keep track of them. The table […]

ContactForm

View demoDownload source

Here’s an implementation of a contact form with PHP and jQuery. Usually, one would only want the message posted by the user to be sent to an email address. This script does that and also saves all these messages in the database for the admin to keep track of them.

The table to store this data is the following:

CREATE TABLE CONTACT(
pk_contact 	INT UNSIGNED NOT NULL auto_increment,
name			VARCHAR(120) NOT NULL,
email 			VARCHAR(120) NOT NULL,
website		VARCHAR(120) NOT NULL DEFAULT "",
message		VARCHAR(300) NOT NULL,
added_date 	TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
primary key(pk_contact)
)type=innodb DEFAULT CHARACTER SET utf8	COLLATE utf8_general_ci;

We will keep track of the name, email, website (optional), the message, and the date when the message was sent. Feel free to change the limits of the fields, but don’t forget to change them as well in the PHP files.

We use jQuery for the front end, and AJAX for submitting the form. All the validations are done on the server side, and the user will be notified when one of the fields is not correct. If the message is inserted into the database, an email is sent to the admin, notifying him about a new message.
We provide two CSS templates for the contact form.

Concerning the installation, all you need to do is run the database script (db_main_script.sql) and configure your database connection in config.php:

define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', 'ContactForm');

You can also configure the email parameters in this file, like the Email Message Subject.

View demoDownload source

Message from TestkingSing up for 642-436 online course to become IT expert. Pass your a+ certification exam on first attempt using scbcd prep material.
Previous:
Next:

Tagged with:

Chadking is an absolute geek that rarely leaves the comfort of his 3-screen desk. He is a self taught programmer and is addicted to all possible legal drugs.

View all contributions by

Website: http://tympanus.net/codrops/author/chadking/

Related Articles

Feedback 29

Comments are closed.
  1. 1

    Great contact form, i have problem with this script the successful message not shown and emails didn’t inserted to db and not sent, it’s was work fine with me but after i changed my hosting company this issue happen and seem the script not working because some php and sql codes if any one could help to fix this issue or use script without insert email to database.
    thank you

  2. 2

    any one can help me to find the php feature which is effect this script working. i think some thing is disabled on my server which is make script not work fine, any one know which feature is that.

  3. 3

    I have set it up perfect. But when you fill in the form and click send you dont get a email.. Can you please help?

  4. 4

    Hi, nice form, however, I can’t seem to get it working. It looks great but when I send something, all it does is loop around and around. I know some people here have pointed that out but unfortunately nobody wants to answer the question. What good is a comments section if no one uses it. Thanks

  5. 5

    tried and tried and never could get it to work, it seemed cool, but it never work, don’t know what I did wrong.

  6. 7

    nice tutorial
    can u pls provide a version without MySQL i.e. only for sending mail wout save

  7. 8

    I tried, tried hard.. but its just not sending, nor does it give error, on clicking submit all it does is tht is shows the loader, please helppppppp….

Comments are closed.