home *** CD-ROM | disk | FTP | other *** search
Wrap
Form To Mail Easy to use script to send mail from a form. Allows use of an e-mail template file, so you can customize the appearance and wording of the e-mail. HTML e-mail option. <?PHP // Form To Mail // This program will process information send // to it via POST from a form on a web site // The form should be set up like this: // <FORM METHOD="post" ACTION="form_to_mail.php3"> // <INPUT TYPE="hidden" NAME="to" VALUE="your@email.com"> // <INPUT TYPE="hidden" NAME="subject" VALUE="The subject can be whatever you want"> // <INPUT TYPE="hidden" NAME="template" VALUE="form.frm"> (optional) // <INPUT TYPE="hidden" NAME="required" VALUE="name,email,comments"> (optional) // <INPUT TYPE="hidden" NAME="redirect" VALUE="thankyou.html"> (optional // <INPUT TYPE="hidden" NAME="html_mail" VALUE="1"> values are 0 or 1. // if the html_mail is set to 1, then your template can be an HTML page. // when using a e-mail template, simply set it up like this: // // This is a cutomized e-mail. Sender's Name: <name>. // The Sender's E-mail address is <email> // etc. // // Where the email template is a text file with the field names contained in <>. // set default send to address if (empty($to)) $to = "your@email.com"; // set default sender's e-mail address if (empty($email)) $from = "FROM: your@email.com"; else $from = "FROM: $email"; if ($html_mail) $from .= "\nContent-type: text/html"; function PrintErrorPage($error_msg) { // change the HTML below to customize your default Error Page ?> <HTML> <HEAD><TITLE>Error</TITLE></HEAD> <BODY> <DIV ALIGN="center"> <TABLE CELLPADDING=8><TR> <TD BGCOLOR="#8A8A8A"><FONT SIZE="+2">Error Processing Form</FONT></TD> </TR><TR> <TD BGCOLOR="#C0C0C0"> <B>Please Use The Back Button On Your Browser And Correct These Mistakes</B> <BR><BR> <?PHP print $error_msg; ?> </TD> </TR></TABLE> </DIV> </BODY></HTML> <?PHP } function PrintSuccessPage() { // change the HTML below to customize your default Success Page ?> <HTML> <HEAD><TITLE>Success</TITLE></HEAD> <BODY> <DIV ALIGN="center"> <FONT SIZE="+1"><B>Thank You. Form Has Been Sent</B></FONT> </DIV> </BODY></HTML> <?PHP } // load required variables into $required_array $required = ereg_replace(" ", "", $required); $required_array = array(); if ($required) $required_array = split(",", $required); // check for required fields $loop = count($required_array); $error_msg = ""; for ($i = 0; $i < $loop; $i++) { if (!$HTTP_POST_VARS[$required_array[$i]]) $error_msg .= "Required Field, ".$required_array[$i].", was left blank<BR>\n"; } if (!$error_msg) { // send the mail and redirect to thank you page $message = ""; if (empty($template) || !file_exists($template)) { while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) { $message .= $key.": ".$val."\n\n"; } } else { $lines = array(); $lines = file($template); $loop = count($lines); for ($i = 0; $i < $loop; $i++) { $message .= $lines[$i]; } while ( list( $key, $val ) = each( $HTTP_POST_VARS ) ) { $message = ereg_replace("<".$key.">", $val, $message); } // at this point, $message is ready to go. } mail($to, $subject, $message, $from); if ($redirect) HEADER("Location: $redirect"); else PrintSuccessPage(); } else { // send error page PrintErrorPage($error_msg); } ?>