Server-side PHP contact form with validation.
Preserved from the old Uncharted Design blog for nostalgia. This is old web-business advice, not current guidance.
The other day I needed a contact form. Simple task right?
After 4 hours of searching I adapted my own. As I see it, this is a proper contact form. Simple, server-side, great validation on the email, one page, and unobtrusive spam protection. The code is simple enough that you can modify it with a little php knowledge, and the css is only two lines.
I stole the original from Jack Franklin at The Web Squeeze – and he deserves most of the credit for this one.

The original demo and download files were not preserved in the static archive.
Change the first line in the php to reflect the address you want the form sent to.
That’s it!
Advanced
The form uses Post to itself. The first if statement in the PHP checks to see if it’s accepting a post, and if so it does a few checks.
Is the name empty? comments? valid email?
If all of those pass, it goes through and attempts to send the mail to the address you specify.
The form is written so that if there are errors, they are displayed. No if statements whatever, if there’s an error it will be echoed, if not then nothing will be echoed.
Spam protection is handled through a honeypot, <div style=”margin:-2em 0 0 -2000px;”>. Bots don’t really care if that form element is in outer space, they will fill in some gibberish anyways. And if they do, it fails out.
If you want more details, check out the original the original Web Squeeze tutorial. He goes quite in depth. If you need more about my modification of it, let me know and I’ll be happy to answer.
