How to correctly make a PHP contact form

Posted on by admin

I use contact forms on many websites, and over the years I have discovered many problems with using them, including hijacking, mail injection, server hacks, XSS and platform issues.

The main cause of this is simply due to lack of validation and error checking.

Firstly you must fully understand how forms work with PHP. When you set the form “method” to POST, it sends the data to PHP as a super global variable called “$_POST”. In the HTML each “input” has a “name”, that is used to identify the related data.

For example, there is an input field named “message”, to retrieve this in PHP you simply use “$_POST['message']“, we will be using this method to pass the data between the form and PHP for processing.

This is a fine example of how NOT to do it, so what is wrong with this method you may ask?

Here are some of the issues we need to overcome:

Download here: PHP Contact Form by HM2K v1.0.1

The comments I have made within the code explains the reason what it does, and why it is included.

I hope this solves some of the problems people experience with contact forms.

Additional Notes:

Related posts:

  1. Contact There are a number of ways to contact us: Find...
  2. Don’t forget to run make test! During my install of PHP5 on FreeBSD… Build complete. Don’t...
  3. exim on another port for smtp When a business I know had trouble with their broadband...
  4. How to Minimize Microsoft Office Outlook to the System Tray Open your registry and find or create the key below....
  5. No Message Alerts Problem on Nokia N95 A couple of weeks ago I noticed that the alerts...

About admin

The author formerly known as HM2K is now the Phurix Labs administrator.

This entry was posted in Development and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>