This blog site is not meant to be any information that is distributed to the general public. It is to serve as shared documentation between the DNSTC developers; however, if you find something useful and would like to use it, go right ahead.

Thursday, March 19, 2009

Quick and Dirty E-mail Form

There may be occasions where you need a quick form to send information to a client.  The form does not have to be anything special, just collect some information and send it off to somebody’s e-mail address.

The following is some code that will submit whatever fields you specify within the form to an e-mail address.

Place the following PHP code within the body tags, (Note: Your site must be PHP capable):

if(!empty($_POST)) { // If something is submitted to this page
$body = "";

// This loop will build the body of the message including every variable
while (list($key, $val) = each($HTTP_POST_VARS)) {
if ($key--> "submit") { // Don't include the sumit key value
$body .= "$key: $val \n"; //Add all fields to the message

$to = "";
$subj = "The subject you want";
$from = "";

mail($to, $subj, $body, "FROM: $from");

// Display a thank you message after the message has been sent.
Thank You for your submission. The results were e-mailed...</blockquote>
<?php } else { ?>

<form method=post action=<?php echo $PHP_SELF; ?>>

... Add the form and fields here ...


<?php } // close the if ?>