From our sponsor: Elevate all your marketing with Mailchimp Smarts.
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.
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
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.
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?
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
tried and tried and never could get it to work, it seemed cool, but it never work, don’t know what I did wrong.
send message in mysql table for gmail ?
nice tutorial
can u pls provide a version without MySQL i.e. only for sending mail wout save
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….
@Madhuri Which link should we look at?