You are here: Home » All Posts » Contact Forms » A simple, easy PHP contact form

A simple, easy PHP contact form

in Contact Forms

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.

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.

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Blogplay

Related posts:

  1. Creating a contact form for your website

{ 64 comments… read them below or add one }

Leo August 31, 2011 at 1:30 pm

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. :)

Reply

Ubiquitous September 8, 2011 at 12:47 am

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!

Reply

Prasanth September 16, 2011 at 7:50 am

try without the captcha perhaps?

Reply

The AntiJoey December 12, 2011 at 6:59 pm

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

Reply

Jenixon September 10, 2011 at 12:32 pm

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

Reply

sam hattem September 22, 2011 at 6:01 am

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

Reply

Jim September 23, 2011 at 9:52 am

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

Reply

Dirk October 1, 2011 at 12:38 pm

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?

Reply

Brad October 5, 2011 at 6:19 pm

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!

Reply

Brad October 5, 2011 at 7:33 pm

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

Reply

Prasanth October 10, 2011 at 3:11 pm
RonK October 16, 2011 at 8:04 am

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?

Reply

RonK October 16, 2011 at 12:13 pm

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

Reply

Nino November 18, 2011 at 4:44 pm

Hey RonK! I see you use the form in different language, so I would like to ask you how do you do it? :D
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!

Reply

Mike Burns October 22, 2011 at 1:32 am

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

Reply

Sessions & Kimball November 5, 2011 at 9:25 am

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
 

Reply

Gay Farace-Mann November 6, 2011 at 5:11 pm

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

Reply

Amit November 9, 2011 at 3:32 am

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

Reply

Micharl Medley November 18, 2011 at 3:52 pm

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”);

Reply

kunal November 22, 2011 at 3:57 pm

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

Reply

katerinaa November 28, 2011 at 10:46 pm

perfect job

Reply

Polo November 29, 2011 at 12:38 am

Brilliant! Thank you 1000 times.

Reply

Seth December 7, 2011 at 9:08 pm

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.

Reply

Ian December 8, 2011 at 5:13 pm

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?

Reply

Alan December 12, 2011 at 3:07 pm

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.

Reply

Leave a Comment

Previous post:

Next post: