PHP E-mail Receive Form Electronic Content TextThere are a number of ways you can process an HTML web form to capture information entered by someone visiting your web site. PHP, with its built-in e-mail function, offers one of the simplest ways to capture such user data. And PHP is rapidly gaining in popularity, so it's easy to find a web hosting company that supports PHP.
Very Basic PHP ScriptPERFECT is a small and efficient PHP script that processes an HTML web form and sends the information in an e-mail message to a predefined recipient.
Automatic Field Detection:Emphasis has been placed on simplicity and reusability rather than on complex features. Think of PERFECT as the "Hello, World" version of PHP web form processing.
Searches the form ("post" data) to find all input fields so that you can modify the HTML web form without having to change the PHP script.
User Host and Browser:
Message includes user's host and browser information.
Hidden E-Mail Address:
E-mail address used by the script is hidden for your protection.
Safe E-Mail Content:
Content of message is stripped of special characters in the off chance that someone attempts to submit malicious content.
Script is easily configured by editing the setup variables at the top of the script.
You are free to use and modify the PERFECT script as you like (it's open source).
PERFECT Script: feedback.php
<?php //////////////////////////////////////////////////////////////// // PERFECT // // ------- // // PHP E-mail Receive Form Electronic Content Text // // File: feedback.php // // Version: 1.8 (April 21, 2008) // // Description: Processes a web form to read the user input // // and then send the data to a predefined recipient. You // // are free to use and modify this script as you like. // // Instructions: Go to "http://www.centerkey.com/php". // // License: Public Domain Software // // // // Center Key Software * www.centerkey.com * Dem Pilafian // //////////////////////////////////////////////////////////////// // Configuration Settings $SendFrom = "Form Feedback <firstname.lastname@example.org>"; $SendTo = "email@example.com"; $SubjectLine = "Feedback Submission"; $ThanksURL = "thanks.html"; //confirmation page // Build Message Body from Web Form Input foreach ($_POST as $Field=>$Value) $MsgBody .= "$Field: $Value\n"; $MsgBody .= "\n" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n" . $_SERVER["HTTP_USER_AGENT"]; $MsgBody = htmlspecialchars($MsgBody, ENT_NOQUOTES); //make safe // Send E-Mail and Direct Browser to Confirmation Page mail($SendTo, $SubjectLine, $MsgBody, "From: $SendFrom"); header("Location: $ThanksURL"); ?>
Sample HTML Web Form
<html> <head> <title>Comment Page</title> </head> <body> <form method=post action="feedback.php"> Your Name: <input type=text name="Name" size=25><br> Your E-Mail: <input type=text name="EMail" size=30><br> Your Comment: <textarea name="Comment" rows=4 cols=30></textarea><br> <input type=submit value="Submit Feedback"> </form> </body> </html>
Sample Feedback Message
To: firstname.lastname@example.org Subject: Feedback Submission From: Form Feedback <email@example.com> Date: Sun, 20 Jan 2008 17:07:26 -0400 Name: Susie EMail: firstname.lastname@example.org Comment: I wish your web site offered search by brand. Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko Firefox/1.0 8214.dsl.isp.net
Instructions (Tutorial)To use PERFECT on your web site:
Sample HTML Code: PERFECT Style and Form
All the fields are optional. However, if you want a response, make sure to provide your e-mail address.
Send Us a Message
Special thanks to Greg for his technical advice in creating PERFECT.
"Just what I needed. Good to know that you are out there. Cheers"
B.D., February 1, 2010
"thanks a million, you are da bomb...."
E.M., October 19, 2009
"Dude! I spent months trying to get so many damn forms to work... Register Global issues, re-direct page issues etc... This script is legendary! Thank you!"
A., October 2, 2009
"Thanks pal, tried a few and none of them worked but this one was brilliant. Thanks again!"
J., September 30, 2009
"This is easy and great - the best and most intuitive form script I ever used. Thank you!"
D., September 25, 2009
"This is ideal! There's dozens out there but most are bloated, feature-strangled, and a whole lot less flexible than the programmer imagined them to be. 5 peppers at hotscripts."
J., May 20, 2009
"GENIUSSSSSS!!!!! Just a PERFECT script"
D.T., April 8, 2009
"This is awesome saves so much time."
M.C., April 7, 2009
"Many thanks. I never thought to solve my message problems with a so short but very efficient script."
A.B., March 7, 2009
"Very easy and straight foward Tutorial. Thanks alot"
C., February 27, 2009
"awesome, this actually works and is simple to understand unlike others... well done and thanks for letting me have this for free, [people like you save me alot of head scratching. thanks again"
R., February 16, 2009
"Thanks for this script! Works great for me its simple but it does the job! Thank You!"
R., February 10, 2009
"That is fantastic mate. 1 go no problem. This website is highly recomended"
A., February 8, 2009
"FANTASTIC SCRIPT! I love you! thank you :-) long live to you"
V., January 14, 2009