A simple, easy PHP contact form

Adding a contact form helps in getting good leads quickly. Contact forms need not be complex. Here is a simple but powerful contact form that you can just download, customize and plug-in to your website.

Also see: more free, modern contact forms from ReusableForms.com

Download the contact form code

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

simple contact form
A simple contact form with three fields: Name, Email and Message
Try the DemoDownload
Another simple contact form
A simple contact form with fields: Name, Email, Phone number and Message
Try the DemoDownload
simple contact form with captcha
A simple contact form with a simple anti-spam mechanism
Try the DemoDownload

Features of the contact form

  • Simple contact form
  • 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('name@your-website.com'); //<<---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

You can edit the contact.css file to change the style of the form. You can add any type of fields to the form. The fields will automatically be included in the form submission emails.

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

License


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

Comments on this entry are closed.

  • Is there a way to send a confirmation  e-mail to the sender(‘s) with some text like thank you for response we will contact you later and other stuff ? it’s not a AddRecipient
    Very useful contact form nice and easy. 🙂

  • I have been building websites for a while now as a “hobby”. I have just starting delving into the realms of PHP. I have successfully integrated a working blog into my existing website. However I am having issues with the contact form I am trying to activate on a website I have done for a friend.
    I have followed the examples shown on this site – the form displays fine, the javascript validators work but no matter what I do I keep getting a “The code does not match. Please enter the code in the image” message. I have done it case sensitive and not.
    I haven’t altered any of the PHP script, merely the HTML and CSS to affect the way it looks.
    I know it is probably something silly I am missing – it always is!

    • try without the captcha perhaps?

      • Ubiquitous,
        Did you ever solve this? I am having the same problem. Captcha just doesn’t work. 1 more hour and I seek another script.

        AJ

  • Help! When you click submit, the only thing that happens is a little text that loads saying success and thats from the captcha text. No email is sent and no page redirection!
    Can you help me please?
    Thanks,
    Jenixon

  • great code only one thing that the form send email even if there is no text in the message area
    i mean what is the point of sending email with no message
    is there a way to add message validation for empty message
    thank you

  • How do I remove this text in the email body which is sent to me from this php contact script:
    Submit :
    Submit
     

  • Great emailer! Works great! However, I need the user to be able to select who they will send the email to. I tried making some routines with radio buttons, but the emails just disappear into oblivion. Any suggestions?

  • Hmmm… when I use this form, the email I receive shows the following in the “from” field:
    From: Joe Schmoe <nobody@mydomain.com>
    Shouldn’t it have Joe Schmoe’s email address there, not “nobody” form my domain?
    Also, how do I modify the format of the email content that gets sent to me (I want to remove the “Sugmit: Submit” lines)
    Thanks!

    • Found this code in bgcontactform.php:
       
      $host = $_SERVER[‘SERVER_NAME’];
      $from =”nobody@$host”;
      return $from;
       
      But can’t figure out how to change the “nobody@$host” to actually reflect the user’s email address

  • I have a peculiar problem.
    First, I’ll say that everything works great.
    When does it not work great? When the “name” of the person filling out the form is in non-English characters. Yes, I use this form in another language and when I use non-English characters in the “name” field, it still sends me the email and includes the “name” field in the email but does not include the “email address” or the “message” that was entered.
    Any ideas?

  • Never mind… I figured it out. It’s in the fgcontactform.php file under the sanitization rules.
    Great code!!! Thanks again!

    • Hey RonK! I see you use the form in different language, so I would like to ask you how do you do it? 😀
      I am trying to translate the from in Macedonian language with Macedonian alphabet characters but all i get is ???? ???? ?? instead of Full Name*, E-Mail Adress* etc.. I tried converting the file in UTF-8 encoding but it doesnt work…

      Help!

  • This was working correctly then all the sudden getting this any clues?  This comes when someone fills out the form and hits submit.  This is the info on the screen.
     
    Deprecated: Function eregi() is deprecated in /home/theholeb/public_html/forms/wholesale/include/fgcontactform.php on line 548

    Deprecated: Function split() is deprecated in /home/theholeb/public_html/forms/wholesale/include/class.phpmailer.php on line 470

  • Hi nice to see the kind information it’s really very helpful for me i also use the development in php in my part time i like the tool that you discuss here i will work on it thanks for sharing the kind information
     
    Regards
    Sessions & kimball
     

  • Thank you for doing this. You have helped me in a time crunch for a project.

  • Exactly what I am looking for.
    Nice explanation and easy to follow.
     
    Many Thanks !!!!

  • Well, everything is working just fine. The only problem is that I need to have the thank you page open in a new window and not inside the form. Can you help me with this.
    Thank you,
    MTMedley
    And I must say this is a great script and very easy to install. 🙂

    $formproc->RedirectToURL(“/thank-you.php”);

  • Hello! Great article!!
    One thing: What do I need to do if I have to show the Thank you msg in same iframe?

  • perfect job

  • Brilliant! Thank you 1000 times.

  • Thanks for the form!

    The only thing I can’t get it to do is work with checkboxes. It only returns the last of the selected values. Any suggestions? It works fine with radio buttons.

  • Hello
    I have a strange problem. When i put the form in an iframe, enter info and click submit, it says i did not pass the validation. If i enter the validation and submit again the form goes through fine.

    If i test the form outside the iframe it works no problem. Any ideas anybody?

  • Love the forms thank you for all your hard work and making these available to us ignorants! Can you tell me whether it is possible to include a BCC as well as the email address for the reply? Thanks.