Simple PHP form (POST) to send e-mail
The sample was simple enough, but thought I should add some explanation since a user had been asking how it works:
- At start it checks if it’s rendering the page the 1st time (same goes if page was refreshed) or if it’s redrawing it as a result of a form POST action (a postback in Microsoft’ ASP.net terminology)
- a) if it’s not a postback, it lays out the HTML elements that make up the form (all input items or items the value of which we don’t want to recalculate every time [if they’re not security critical that is since readonly form field values can be edited by hackers] should be enclosed in FORM tag)
b) if it’s a postback, it grabs the form fields (by name), constructs $emailsend variable (shown in multiple steps above for overview of the resulting e-mail), then calls mail function of PHP to send the e-mail (from value is hardcoded in that call, will usually need to be a value that your server allows, like “someone@yourserverdomain”)
Note: If form should send e-mail to you, don’t allow user to set the TO field (remove it, don’t just make it readonly else hackers can exploit to send spam to others via your server) and hardcode it in the mail function call.
Update: Since the above URL is now broken, I suggest you use the free FormToEmail PHP script (or if you don’t have a PHP host try their free FormToEmailRemote service) for e-mailing feedback forms. Both these offerings also have a "Pro" version you can register if you need more advanced features like CAPTCHA etc.