How to embed the contact form in your web pages

This page shows you how to embed the contact form (see the free contact forms from HTML Form Guide) in a web page. Different methods are shown; you can decide which the best is, for you.

Using IFrame

Using Iframe is the easiest way to embed the form in your web page. Iframe lets you create a box on your web page whose contents are loaded from another URL. Here is a sample iframe code:

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

Update the src attribute with the URL path to your contact form. In order to avoid scrollbar from appearing, you can adjust the value of the ‘height’ attribute.

Including a header and footer in the contact form page

Another way to embed the contact form is to have a common header and footer across your website. You can include the header and footer in the contactform.php.

This method allows you to preserve the same look across the website.

Here is some sample code that illustrates this method.

Including the header:


<!--Note: The header is included here -->
<?php include('../includes/header.php'); ?>

<!-- The form start from here-->
<form id='contactus' action='<?php echo $formproc->GetSelfScript(); ?>' method='post'>
<fieldset >

Including the footer:


<!-- Note: Here we include the footer -->
<?php include('../includes/footer.php'); ?>


Comments on this entry are closed.

  • Thanx a mil!
    Got my contact form fixed by using a simple iframe!

  • Thank you so much for this contact form.
    I embedded it using i-frame and it works a treat!

  • I guess i’m doing something wrong, but i’ve embedded the form into my web page with the iframe html, but the iframe is blank when i open the page.  Any ideas?

    • Juz, are you trying it on your local machine or up on the web? Unless you have a php testbed, you wont see anything on a local machine.

  • Ok I’m dumb but the iframe line makes a call for contactus.php and there was no such file in the zip. So I chranged it contactform.php and all that did was load the file into wordpad. Thought this was a drop and go but obviously not.

    • You need PHP on your web server

    • Sunguy . . . your brain is getting boiled by too much sun . . . this is simple stuff, just read and apply!!!

  • Hi,
    Great script you have here. I have one question though — how do you reduce the default size of the message box? Thanks in advance!

  • I have followed the instructions and I missing something (or a lot of things!) as I get an error message ‘file or directory not found’.
    Any help would be greatly appreciated.

  • Can any one help me to add a another field as Combo box to this form, I don’t know PHP. I know little bit of HTML/CSS.
    Thanks for your support.

  • Greetings,
    I just installed php on my server (win 2k8 r2, IIS7), and I can’t get the form to submit.
    It seems to be running into an issue somewhere around here:


    I added the “else” myself, because it was just refreshing the page when I hit submit. With that line added in, it indeed redirect to the error1.htm. Any suggestions?

  • GREAT!!! You guys deserve the respect from all GNU’s around the world…

  • Andrew, I have the same problem as you have , did you solve it ?
    the form is not submitting !!!
    I’ve added the same page , and I get the same error all the time.


  • Hi guys, great form andim nearly there with installing it. Im just testing it and when I click submit, i just get a ‘connection was reset’ error. Any ideas what may be causing this? If this is obvious, well, I am a novice.

  • I’m sooooooooo thankful for sharing with this – i was dancing and screaming when i loaded this 🙂 Thank You Thank YOu !!!!!!

    • where we write down the mail id where form detail submitted

    • his going through outlook express

  • Hey, you guys are awesome! The contact form works beautifully. One question, is there an easy way to have a new window open after the submit button is clicked? I have the contact form iframed and I want it to redirect to a completely new page but it just iframes the new page within my contact form page.

  • Can this be embedded into Facebook?

  • Great stuff, but I must be doing something wrong. The captcha image does not appear on What could I be doing wrong?

  • can someone help me, I followed all the directions and got a blank screen on google chrome and got an http 500 “website cannot display the image” error on IE. I changed the name to contactform.php and even put it into subfolder after trying it directly in httpdocs. I am using parallels plesk hosting. any help would be great, thank you!

  • same problem as Bilal and Andrew, it just refreshes and when I add the else statement it only opens the error page.
    I have the same infrastructure as Andrew.

  • I must be doing something wrong, but the captcha image does not appear on on my website either. Anyone with the same problem? How can I fix it?

  • I’m so sorry but i just to learn how to build a website. I just don’t understand what does it means by “Update the src attribute with the URL path to your contact form”. Can somebody explain it to me if possible in details. Thank you very much.

  • Hi, I used Iframe to embed the form on my contact page. I have it redirecting after form is completed to my index page, the problem now is my index page is showing in a Iframe? Is there a solution to stop this? Any help would be greatly appreciated.


    Happy Holidays. Thanks for the script it works very well! Cheers!