Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

CornerBLUE, Inc. http://www.cornerblue.com

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

PHP: Email All Form Values

If you need a very basic contact form and don't want to write extra code for putting the value of each field into the email, you can use this basic email. It works best if you name your form fields something legible, such as First_Name

if (isset($_POST['Submit'])) {
	// Prepare message
	$msg = "Time: " . date("m/d/y g:ia", time()) . "\n";
	foreach ($_POST as $field=>$value) {
		if ($field != "submit") $msg .= $field . ": " . $value . "\n";
	}
	
	if (mail("TOEMAIL", "SUBJECT", $msg, "From: FROM_NAME <FROM@ADDRESS.com>")) {
		// Email was sent
	} else {
		// Erro sending email
	}
}

PHP: Pass On Values For A Multi-Page Form

While the best way to do this involves saving the data into a database and passing an encrypted reference to the next page, this method will suffice for non-critical uses.

foreach ($_POST as $field=>$value) {
	echo "<input type=\"hidden\" name=\"" . $field . "\" value=\"" . $value . "\" />";
}
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS