Creating a contact form for your website

Here is a ‘ready to use’ form that you can simply plug-in to your web site. All that you have to do is to download the code below, update the code to include your email, and attach form to your web site.
You can easily customize the form for your needs. The code is 100% validated XHTML1.0 strict.

Also see: free form downloads from

Features of this contact form

  • Standards compliant, accessible form
  • 100% XHTML 1.0 strict validated, uses CSS2
  • Secured against spam and attacks
  • Validations done both on client side and on the server side
  • Uses PHPMail to send email
  • Easy to customize
  • Hosted on your own web server
  • Free!

Download the contact form code

You can download the contact form that best fits your needs and then customize as required.

Simple contact form with three fields: Name, Email and Message
Try the DemoDownload
Contact form with simple captcha
Contact form with Simple Captcha
Try the DemoDownload
contact form with image captcha
Contact form with fields: Name, Email, Phone and Message (and Image Captcha)
Try the DemoDownload

Installing the contact form on your web site

  1. Unzip the downloaded contact form code.
  2. Edit contactform.php and edit the email address to your email address
    $formproc->AddRecipient('');//<<---Put your email address here
  3. Upload the folder contents to your website (to a sub-folder say, /contact)
  4. The contactform.php contains the form. You can link to this file or embed the form using iframe.

Sample iframe code to embed the form:

<iframe src='/contact/contactus.php' frameborder='0' width='100%' height='600' ></iframe>

Alternatively, you can modify contactform.php to have the same look of your web site.

Customizing the form

The contact form can be customized to match requirements. You can change the style, add more fields, and add more email recipients.

Changing the colors, fonts and style

You can edit the contact.css file to change the style of the form.

Adding more than one recipients

Call the AddRecipient() function passing the email address of the new recipient.Example:


Adding more fields

You can add any type of additional fields to the form. The fields will automatically be included in the form submission emails.

More Customizations …

For more features and customizations of the contact form, see the Related Pages section below.


The code is shared under LGPL license. You can freely use it on commercial or non-commercial websites.

Comments on this entry are closed.

  • Still can’t get captcha form to work with IIS. PHP is working on IIS. Can get the non captcha form to work. Can get other simple captcha displays to work stand alone but the the captcha just doen’t come up.  It works fine on a XAAMP server by changing a couple of the outdated calls. Make the same changes and try it on a IIS no dice.

  • Great stuff guys. 2 Questions.
    1) Can I have more than one form on a page
    2) When I want to add fields do I have to make changes inside the fgcontactforms.php or only in the source code.
    Email Address*:
    <input type='text' name='email' id='email' value='SafeDisplay(’email’) ?>’ maxlength=”50″ />

    Make changes inside the div tag and copy and paste???

    • Dunno if you ever figured this out, but:
      1)Yes, I created an entire new instance of everything, changing the folder and file names to something else (e.g., contactform/contactform.php to contact2form/contact2form.php). Don’t forget to change all instances of includes, requires, etc to match the different names.
      2) You can add any input element to the form that you wish without altering fgcontactforms.php.

      Hope this was helpful.


  • PS Happy Thanks Giving

  • Great form! Thank you for sharing!!!
    The only question I have is how can I remove the border frame that starts after the ‘Contact us’?

    • One more question, how can I display the required field error message inside the text input text field.

  • I have added a dropdown list () inside the form.

    When I am getting the mail the dropdown list name is there but no value is there.

    How can I fix this problem?

    Plz help.

  • Thank you for your generosity on sharing all this code!!!

    I used your pop-form in one application and it worked great. I am now trying to use the simple php contact form for a different application and have run into an issue. The form works – it sends email and I can receive it as well. However, I am getting an error message above the form on the page where the form is displayed.
    Warning: session_start() [function.session-start]: Cannot send session cache limiter – headers already sent (output started at /home/content/t/e/r/t/html/website/contact.php:7)
    in /home/content/t/e/r/t/html/website/include/fgcontactform.php on line 63
    Would you have any suggestions on how to eliminate this message?
    Thanks again.

  • Thanks! This form is just what I was looking for. I have been struggling with a e-mail contact us form for a while and this just worked in 5 minutes.

    One question… the e-mails that are sent sometimes end up in the junk folder. Do you have any suggestions?

    Thank you so much!!!

  • Having a Hard Time with the Captcha’s. Im kinda retarded with this stuff any help would be great. the image isn’t loading on the page from what i see the Script is all correct and i uploaded the files to the /contact dir. to keep it seperate from anything else on my site, im not having any luck with the image file. what might i be missing.

  • I’m testing the simple testing form locally, when I click the submit, I have this error:

    Deprecated: Function eregi() is deprecated in C:\Users\jmelendez.SABIAMED\xampp\htdocs\PhpFormValidator\samples\3-with-client-side-validations\include\formvalidator.php on line 237

    Thanks for the help…

    • Ok, I fix that…

      Now when I complete the fields a click submit, the thank_you page is not display.

      Some idea? I’m testing locally.

  • thank you

  • omg i have searched all day for a “WORKING” contact form that not only processes the data but also uses captcha and jquery validation … you think something like this would be easy to find …. alas no! if you had a G+ or FB Like button id be maniacally stabbing it at this point
    THANK YOU SO MUCH for posting this!


  • Thank you so much – as a complete novice, this was amazing for me to find! However, the Frame needed me to change …/contactus.php to ….. /contactform.php . took me a while to figure that one out, but now I have.


  • A thousand thanks.

    This form is precisely what I needed, and to develop it myself would have been prohibitively time-consuming. The time and effort that I would otherwise have grudgingly spent designing a form (which would probably require multiple rounds of revisions to make it work) are now free for me to use developing content instead.

    (Note about my site: is not yet formally open: All the subdomain index pages are isolated and merely advise “Coming soon.” If you want a sneak preview, click on “” by way of a representative page.)

  • Hi all,

    Has anyone managed to enable attachment capabilities for this? If so, how?

    It seems that all one would need is to add enctype=’multipart/form-data’ to form tag, then

    Select A File To Upload:

    to the form itself. fgcontactform.php should just pick up the rest, but alas, it does not.

    TIA for any clues!


    • Tags were stripped from the above message. Should read:
      <div class='container'>
      <label for='attachment'>Select A File To Upload:</label>
      <input type='file' name='attachment'>

    • Here’s how it can be done. Edit contactform.php thusly:

      Add enctype=’multipart/form-data€™ within the form tag

      Add the following to the form itself:
      <div class='container'>
      <label for='attachment'>Select A File To Upload:</label>
      <input type='file' name='attachment'>
      <span id='contactus_attachment_errorloc' class='error'></span>

      After this line (about line 21):
      Add this:

      Within the javascript at the bottom of the file, add the following:
      [code]frmvalidator.addValidation("attachment","file_extn=jpg;jpeg;gif;png;bmp","Upload images only. Supported file types are: jpg,gif,png,bmp");[/code]

      Hope this helps someone out there!


  • hi,
    newbie at webdesign and it seems like this contact page is just what i need. however the first instruction where it says to replace my email i can not find. where exactly is that in the code?

    • I don’t know if you’ve found the correct insertion spot since your comment was posted, but in case you haven’t, look on line 19.

      It should look something like this: “$formproc->AddRecipient(‘’); //<<—Put your email address here"

      Just substitute your contact email address for ""

  • showing this error, my siite hosted on blogger, i uploaded my files to

    Fatal error: require_once() [function.require]: Failed opening required ‘./include/fgcontactform.php’ (include_path=’.:/usr/share/php’) in /www/ on line 9

  • I’m getting these errors after submitting, any ideas….???

    Warning: date() []: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Denver’ for ‘MST/-7.0/no DST’ instead in /home/content/95/8144395/html/contact/include/class.phpmailer.php on line 1612

    Warning: date() []: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/Denver’ for ‘MST/-7.0/no DST’ instead in /home/content/95/8144395/html/contact/include/class.phpmailer.php on line 1616

    Warning: Cannot modify header information – headers already sent by (output started at /home/content/95/8144395/html/contact/include/class.phpmailer.php:1612) in /home/content/95/8144395/html/contact/include/fgcontactform.php on lin

    • lol, oh adding this will solve in ur phph file.

  • Any ideas on how I can prevent recipients email ending up in spam folder?

  • Is there any way to modify the contact-form code to create an embedded comment module?

  • How can I get the upload feature to be “required” if no file is selected to upload?