Design by Elle

{ designer; developer; freelance; }

PHP Simple Contact Form

Posted on May 09, 2008 / 5 Comments / Permalink

As requested, here is the contact form that I have created and have been using for a long time. Again, should be very simple to implement in your web page. Performs validation of: name, email, subject and message. No need for PHP knowledge. The script is well commented. Form is styled using CSS.

This script is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. This script is distributed in the hope that it will be useful, but without any warranty. Let me know what you think.

Form Installation Instructions:

  1. You need to include (or require) the fns.php at the top of your page. Basically check the index.php and copy/paste whatever is in the php tags at the top and bottom to your page. You will need to adjust the path/to/fns.php
  2. Copy/paste the code within the #contactform div to where you want it to be on your page
  3. Change the email address in the fns.php. You can also change the anti-spam question

Download

Simple Contact Form Script (.zip, 8kb)

Update

The script has been updated to remember entered values if there are any errors and to clear field values when the form is submitted. I also added an anti-spam question protection based on Mike Cherim’s advice on Protecting Forms from Spam-Bots

Comments

  1. Hi. Sorry, i'm new to php,

    I'm trying to add a "file attachment" function to my form...but i have a hard time understanding the instructions

    i hope you can help me.

    — Jason , May 26, 2008

  2. Jason,

    First of all you are downloading a contact form only. Check the other script for file attachment function.

    Second, the download includes 2 files. Check the start of the index.php file to see how to require() the fns.php.

    You will also need to open fns.php in a text editor, find the var that defines where to send the email and change it (it is also commented).

    In regards to point 2 in the instructions, you should at least know HTML.

    HTH

    Elle , May 26, 2008

  3. How can I make the file attachment a required field? Thanks.

    Reynaldo , September 27, 2008

  4. @Reynaldo: You are downloading the wrong script. Try this one. Just added an option to make file attachment required.

    Elle , October 01, 2008

  5. thankyou,thankyou,thankyou..
    you have been a life saver.

    having spent many many months and quite a bit of money on php books i came to the sorry conclusion that php script writing was beyond my none analytical brain.

    i only wish i'd ventured upon your site 18 months ago! still better late than never.

    mind you 'the proof of the pudding is in the eating,' so i may be back crying for help when i finally upload this website i've knocked up for a friend in a few weeks ...still one thing at a time.just hope my nerve holds out!!

    — steve , November 30, 2008

Sorry, comments are closed for this article