PHP

ID #56

Do you have a quick form mail script?

Applies to: Grid System

Here is a quick script that will email all values of a submitted web form.

Just select it all with your mouse while holding down the left mouse button. Select from beginning (including the beginning <?) to the end (including the last </form> tag) below. Then use the key combination CONTROL+C to copy the text. Paste it into the document that will be your webpage.

Make sure you save this file with a filename ending in .phtml or .php, NOT .html or .htm.

<?
/* this part can either be in the same file as the form or it can be in a different file. If you want this in a different file, make the "action" of the form go to that file */

if(sizeof($_POST)) {
$body = "";
while(list($key, $val) = each($HTTP_POST_VARS)) {
$body .= "$key: $val \n";
}

mail("youraddress@yourdomain.com", // to
"Subject Line",
$body);

echo "Thanks for your submission. The results were mailed.";
}

// end form processing
?>

<form
method=post
action=<? echo $PHP_SELF; ?>>
<input type=text name=whatever>
<input type=radio name=this value=radioval>
<select name=another>
<option value=sel1>Select 1
<option value=sel2>Select 2
</select>
<input type=submit name=submit>
</form>


Last update: 2011-01-04 16:29
Author: FAQ Admin
Revision: 1.2

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 0 (0 Votes)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ

Comment of Anonymous:
If you want to expand this script, see the tutorial on dealing with html forms in PHP:

http://www.php.net/manual/en/tutorial.forms.php
Added at: 2003-01-26 21:29

Comment of Anonymous:
If you also want to save the feedback to a file, then insert this code before the closing ?> tag in the script above:

$file = "/htdocs/www/private/feedback.txt";
$fp = @fopen($file, 'a');
fwrite($fp, $body);
fclose($fp);

You will need to create the directory named "private" under /htdocs/www and also password protect it: http://www.modwest.com/help/kb.phtml?cat=1&qid=32
Added at: 2004-03-07 20:25

Comment of Anonymous:
Try this simple plug-and-play PHP HTML Formatted Form Mail Script.

This script is to best to send Form Data in HTML Format. This is compatible with PHP 5.0.3 & Outlook

You can simply download this from:
http://www.webmultimediadesigner.com/wmdformmailer.zip
Added at: 2005-04-24 13:52

Comment of Anonymous:
To make this PHP script work with PHP5,
change the 'while' section of the loop

while(list($key, $val) = each($HTTP_POST_VARS)) {
$body .= "$key: $val \n";
}

to:

foreach ($_POST as $key=>$val)
{
$body .= "$key: $val \n";
}


Added at: 2007-01-28 10:22

Comment of Anonymous:
This allows form values to be arrays, like multi-select menus and checkbox groups. It assumes that "form_page.html" is the page with the html form on it that has action="this_script.php" where this_script.php is the name of the file in the same directory as form_page.html with the following code:



Added at: 2008-02-02 08:31