Making a contact form with file upload support

Having file upload boxes in contact forms will be greatly convenient for some web sites. For example, if the visitor can attach his/her photo and resume, that will greatly enhance the form’s functionality. Here is a contact form that you can customize for your needs.

Also see free file attachment forms from

Download the contact form code

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

Contact form with file attachment
A simple contact form with a file upload field
Try the DemoDownload
Contact form with file attachment and Captcha
Contact form with file upload field and Captcha
Try the DemoDownload
Contact form with file uploads
Contact form with two file upload fields and Captcha
Try the DemoDownload

Features of the contact form

  • You can have any number of file upload boxes
  • Standards compliant (100% XHTML 1.0 strict validated, uses CSS)
  • Secured against spam bots and attacks
  • Easy to customize
  • Hosted on your own web server
  • Free!

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
  3. $formproc->AddRecipient('');//<<---Put your email address here
  4. Upload the folder contents to your website (to a sub-folder say, /contact)
  5. The contactform.php contains the form. You can link to this file or embed the form using iframe.
  6. Here is 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

If you want to add one more file upload box, do the following:

  1. open contactus.php in a text editor
  2. Add the HTML code for the file upload box(just like the existing one for the photo). Gove another unique name and id for the file upload box
  3. <div class='container'>
        <label for='photo' >Another upload:</label><br/>
        <input type="file" name='newupload' id='newupload' /><br/>
        <span id='contactus_newupload_errorloc' class='error'></span>
  4. Add one more line on the top of the contactus.php
  5. $formproc->AddFileUploadField('photo','jpg,jpeg,gif,png,bmp',2024);
    $formproc->AddFileUploadField('newupload','',2024);//<<------- New file upload

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


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

Comments on this entry are closed.

  • This is great. I work for a company that manufactures Harley parts. Need this attachment form to allow the customers to upload their photos to me so I can post them on our web site. Problem being I copied the file upload box to allow more than one file to be uploaded. It all works fine but only one of hte attachments comes through. Any thoughts?


    • Hi Johnny,

      I had the same problem. Make sure that you have included the line mentioned in step 3..Add one more line on the top of the contactus.php”:

      If I remember correctly I solved my problem like that. Now I’m struggling with the size of the file to be uploaded. Apparently I can receive only very small files. Does anyone know how to increase the allowed size of the file? Any hint is wellcome !!

      • Hi Maria,

        You can increase the accepted file size by changing the number “2024” which you have right now. That 2024 means your form will accept only up to 2mb files. If you want to accept 5mb files, use “5120”. (5 * 1024). Make sure you have used the same number all over the files.

  • Hello There,

    I’m Using the current form that you have been providing. It works great but I need to know how to attach ms word document instead of photo.

    Please advise


  • Hello,

    First of all, this an awesome contact form. Great job for making it accessible to all.

    I followed the instructions and everything works perfectly. The file is attached and send, but after that I get those errors instead of the thank you page:

    Deprecated: Function eregi() is deprecated in /contact/include/fgcontactform.php on line 548

    Deprecated: Function set_magic_quotes_runtime() is deprecated in /contact/include/class.phpmailer.php on line 1218

    Deprecated: Function set_magic_quotes_runtime() is deprecated in /contact/include/class.phpmailer.php on line 1222

    Deprecated: Function split() is deprecated in /contact/include/class.phpmailer.php on line 470

    Warning: Cannot modify header information – headers already sent by (output started at /contact/include/fgcontactform.php:548) in /contact/include/fgcontactform.php on line 143

    I have no idea how to fix this and I have no clue in php programming.

    Please, advise.

  • I am having the same problem as Ben: Great form but the error €œThe file is too big€¦ € does not work. The form is here I downloaded the zip file and copied the files exactly in the same structure. The only change I made to any files is the email where the form is sent in contactform.php. I never receive the file too big error. Then the email will send but with no attachment of course. Can anyone help?

  • Thanks for this.
    Just wondering if there’s a way of adding a BCC recipient?
    Thanks again.

  • Hi,

    i have included a drop down list in the form, i need the code to send the mail depending on the drop down list selected…….

  • Thank you very very much. Congratulations. I’m really happy and it works perfectly.

  • Btw, thanks for this great site !

  • Thanks for sharing!!

  • I can’t create the folder named ‘include’ ! Why ?

  • Thanks for the form, but I have a problem.
    The form works and i recieve the email, but after clicking on the submit button it’s not going to he thanks-page. I get to see:

    Deprecated: Function eregi() is deprecated in /public/sites/ on line 548

    Deprecated: Function split() is deprecated in /public/sites/ on line 470

    Warning: Cannot modify header information – headers already sent by (output started at /public/sites/ in /public/sites/ on line 143

    Does anyone have a idea how to solve this?

  • Hi,

    I have embedded the ‘contactform.php’ file in a on my website, and when I view it on my pc on which the site is created, it shows perfectly, but as soon as I upload all the files, the place where I embedded the ‘contactform.php’ file, remains blank. Why would this be?

    Please help?

  • This form doesn’t appear to work in IE?

  • Doesn’t seem to work with firefox either? Only Chrome? is there something on the browsers that have to be enabled? If so – does this present a problem for the average user coming to the page and filling out the form?

    • Click the Try the Demo link above. does it work in IE & FF ?

  • I re-tried using the contact form, it’s displaying finally, but now I keep on getting and error that says:

    Deprecated: Function eregi() is deprecated in /usr/www/users/ageleqjpdc/quote/include/fgcontactform.php on line 548

    And line 548 in the fgcontactform.php file looks like this:

    return eregi(“^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$”, $email);

    Can anybody advise me what do to please?

  • Hello,

    It works perfectly but how can I modify the code for french message (é,à,…) ?
    Thank you for help.

  • Getting the below error… Any help will be much appreciated… Thanks…

    Fatal error: Call to undefined function imagettfbbox() in /home/cgfpl/public_html/contact/include/captcha-creator.php on line 154

    • install GD library for PHP

  • When I checked for GD, it is installed… Any help will be much appreciated… Thanks in advance…


    GD Support enabled
    GD Version bundled (2.0.34 compatible)
    GIF Read Support enabled
    GIF Create Support enabled
    JPEG Support enabled
    libJPEG Version 6b
    PNG Support enabled
    libPNG Version 1.2.10
    WBMP Support enabled
    XPM Support enabled
    XBM Support enabled

    Directive Local Value Master Value
    gd.jpeg_ignore_warning 0 0

  • Hello, I was wondering if it’s possible to designate only a specific iframe for the the contact form with upload attachment. It seems the script is replacing each and every instance of an iframe with the contact form for some reason?

  • Hi, I’m trying to incorporate this form into Wordpress.
    Unfortunately an iframe isn’t an option for me as the email address are going to be dynamic and change depending on the current page title.

    After multiple attempts, if I was to include ‘fgcontactform.php’ and put it in the relevant place as per your instruction – it bugs out with no error code and prevents the rest of Wordpress from loading.

    I was be very grateful if I can have some help with this?

    Thank you in advance!!

    • For wordpress, there are wordpress contact form plugins that you may try.