May 1st, 2009:
- 8 GB SDHC Class 6 Flash Memory Card
- Register Your Domain Name Now - Only $ 9.99/year
- New Google Chrome Web Browser
- Apple Safari 3 Web Browser - Now on Windows
- Glossary of Webmaster Terms
- HTML Tutorial - Learn HTML
- The history of SEO - Search Engine Optimization
- Download PuTTy - Telent and SSH Client
PHP Contact Mail Feedback Form Script
This is the form that goes into your HTML page:
<form method="post" action="sendmail.php"> <?php if (isset($error_message)) { ?> <div style="background-color:#ff6666;font-weight:bold;text-align:center;color:black;"> <?php print $error_message; ?> </div> <?php } ?> <input type="hidden" name="submit" value="1" /> Your Email: <font color="Red">*</font> <br> <input name="email" type="text" /> <br /> First Name: <br> <input name="firstname" type="text" /> <br /> Last Name: <br> <input name="lastname" type="text" /> <br /> Message Subject: <br> <input name="messagesubject" type="text" /> <br /> Your Message: <br /> <textarea name="message" rows="10" cols="55"></textarea> <br /> <input type="submit" /> </form>
This is the PHP mail or contact form script that goes into your sendmail.php file:
(Example webmasterseminar.com) Replace "webmasterseminar.com" with your domain.<?php //~~~~~~~~~~~~~~~~ // Configuration // define('ALLOWED_DOMAINS', 'webmasterseminar.com,www.webmasterseminar.com'); define('RECIPIENT', 'info@webmasterseminar.com'); define('SUBJECT', 'Info Request - WebmasterSeminar.com'); define('REDIRECT_BAD_REFERER', 'http://webmasterseminar.com/error.html'); define('REDIRECT_SUCCESS', 'http://webmasterseminar.com/thank_you.html'); define('NL', "\n"); //~~~~~~~~~~~~~~~~ // Start session // session_start(); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // The mail will only be send if: // - submit was set // - email was set // - message was set // - session variable "x" was set // - email is not empty // - message is not empty // - session variable "x" matches "spam" // Otherwise an error message will be set and displayed on the contact page. // if (isset($_POST['submit']) && isset($_POST['email']) && isset($_POST['message']) && isset($_SESSION['x']) && trim($_POST['email']) != '' && trim($_POST['message']) != '' && $_SESSION['x'] == 'spam') { // wait one second to avoid flodding sleep(1); //~~~~~~~~~~~~~~~~~~~~~~ // Check if POST came // from allowed domain // $bad_referer = true; $referer = $_SERVER['HTTP_REFERER']; $allowed_domains = explode(',', ALLOWED_DOMAINS); for ($i = 0; $i < sizeof($allowed_domains); $i++) { if (strtolower(substr($referer, 7, strlen($allowed_domains[$i]))) == strtolower($allowed_domains[$i])){ $bad_referer = false; break; } else { $bad_referer = true; } } if ($bad_referer === true) { print '<pre>'; print_r($referer); print '</pre>'; exit; header('Location: ' . REDIRECT_BAD_REFERER); exit; } //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Get POST data, // submitted data is cut off at 150 characters for name and email, // and 10000 characters for the message // $firstname = substr(trim($_POST['firstname']), 0, 150); $lastname = substr(trim($_POST['lastname']), 0, 150); $messagesubject = substr(trim($_POST['messagesubject']), 0, 350); $email = substr(trim($_POST['email']), 0, 150); $message = substr(trim($_POST['message']), 0, 10000); //~~~~~~~~~~~~ // Send mail // $mail = 'The following Message was sent to you from WebmasterSeminar.com:' . NL . NL; $mail .= ($firstname != '') ? 'First Name: ' . $firstname . NL : false; $mail .= ($lastname != '') ? 'Last Name: ' . $lastname . NL : false; $mail .= ($messagesubject != '') ? 'Message Subject: ' . $messagesubject . NL : false; $mail .= 'Email: ' . $email . NL . NL; $mail .= $message; $mail = str_replace("\r", '', $mail); mail(RECIPIENT, SUBJECT, $mail, 'From: ' . $email . NL . 'X-Mailer: WembasterSeminar.com Mail Robot' . NL); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Redirect to REDIRECT_SUCCESS page // header('Location: ' . REDIRECT_SUCCESS); exit; } else { //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // Set session cookie as attempt to avoid // automated spam scams // $_SESSION['x'] = 'spam'; if (isset($_POST['submit'])) { $error_message = 'Your email could not be send, please fill in all required fields'; } } ?>
LINK TO THIS TUTORIAL:
Copy the code below and paste into your web page
<a href="http://www.webmasterseminar.com/phpcontactformscript.php"> Webmaster Seminar</a><br /> PHP - Contact form script, feedback form script - free to use