///////////////////////////////////////////////////////////////////// // // Name : Contact Form // Author : Dan Kreft (bigdan@kreft.net) // Date : Who keeps track of such things? // Description : E-mail contact form with support for cookies. // Requires : PHP version >= 3.0 // // Copyright (C) 2000, Daniel L. Kreft // // Use at your own risk. No warranty, express or implied, etc., etc., // blah, blah, blah. If you modify anything outside of the configuration // block, please send me a diff or a copy of your altered source...if // your changes are cool, I'd like to put them in my own script! // ///////////////////////////////////////////////////////////////////// // // BEGIN CONFIGURATION // // Address to which e-mail will be sent. If sending to more than one // address, separate by commas. define(TO, "dan@kreft.net"); // Size and maximum length for the Name: field define(NAME_INPUT_SIZE, 45); define(NAME_MAXLENGTH, 45); // Size and maximum length for the Email: field define(EMAIL_INPUT_SIZE, 45); define(EMAIL_MAXLENGTH, 45); // Size and maximum length for the Subject: field define(SUBJECT_INPUT_SIZE, 45); define(SUBJECT_MAXLENGTH, 128); // Dimensions of the TEXTAREA box define(CONTENT_ROWS, 9); define(CONTENT_COLS, 74); // Labels for the buttons define(SUBMIT_BUTTON, "Shoot"); define(CANCEL_BUTTON, "Never Mind"); // Messages displayed for successful and missing info cases define(SUCCESS_MESSAGE, "Thank you. Your message has been sent."); define(MISSING_INFO_MESSAGE, "Whoa! Slow down, Cap'n Chaos!"); // // END CONFIGURATION // ///////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////// // // HELPER FUNCTIONS // // verify_data(NAME, EMAIL, SUBJECT, CONTENT, ERRORS) // // This function performs some simple tests on the data passed in // and stuffs error messages into the $errlist array. All arguments // are passed by reference. There is no return value. // function verify_data(&$name, &$email, &$subject, &$content, &$errlist) { if ( !$name ) { $errlist[] = "Your momma didn't give you a name?"; } if ( !$email ) { $errlist[] = "What's your e-mail address?"; } if ( !$subject ) { $subject = "Contact!"; } if ( !$content ) { $errlist[] = "Don't you want to say something?"; } } // // END HELPER FUNCTIONS // ///////////////////////////////////////////////////////////////////// // If we're canceling the submission, we'll redirect to the home page // (in this case, "http://the.kreft.net/"). Otherwise we set a cookie // on the user's machine to keep track of the send...this could be used // to prevent a user from e-mailing you from this form too often, or // you might even want to put up a personalized greeting based upon // the existence of this cookie on their machine ("Hey, thanks for the // e-mail you sent a while back!") or something cheesy like that. :-) // if ( $action == CANCEL_BUTTON ) { header("Location: http://$HTTP_HOST"); } elseif ( $action == SUBMIT_BUTTON ) { setcookie("sent_email", time(), NULL, "/", ".kreft.net"); } // This inserts the document top require "./top.html"; // Clean out the html escape characters and backslashes that might have // found their way into various fields during the POST. // $name = htmlspecialchars(stripslashes($name)); $subject = htmlspecialchars(stripslashes($subject)); $content = htmlspecialchars(stripslashes($content)); if ( $action == SUBMIT_BUTTON ) { // Check data. If there are screw-ups, they'll be returned // in the $booboo[] array. If there are no booboos found, // we'll go ahead and send off the e-mail. verify_data($name, $email, $subject, $content, &$booboo); if ( $booboo ) { printf("
\n\n", SUCCESS_MESSAGE); } } else { require("./form.html"); } require "./bottom.html"; ?>