![]() Line 27 is where the captcha is calculated. All email addresses must have an (at) and a "." (dot). Line 26 checks whether the email address entered is formatted correctly. If a field is blank, a standard error message will be shown. ![]() All error messages can be customized with HTML. Lines 25 - 27: This is where our error handling occurs. This line prevents the script from giving an error message when captcha is disabled. Line 22: This line is only in place in the event you want to disable captcha. The two hidden fields and their respective values are also shown in the label for the anti-spam box. The visible field is where the sum of those two numbers must be entered. ![]() The two that are hidden will each have their respective values set to the random numbers that we generated above. Two of these are hidden, and one is visible. As for the captcha, what happens when the page is loaded is there are three form fields created for the anti-spam portion. Name, email address & message are all strait forward. Lines 13 - 19: This is where our script captures the data submitted on the form. These lines define what those two numbers will be. In order to successfully submit the contact form, the user must answer a simple math question (i.e.: 4 + 9 = ?). In this case, these lines of code generates two random numbers between 1 and 9. Lines 10 & 11: This defines what variables to use in the captcha. Configure these options to suit your needs. This includes options such as where the contact form will email to, the subject of that email, and whether or not to enable the captcha (anti-spam) option. Lines 2 - 8: Use this section to configure your contact form. Mail(EMAIL_TO, EMAIL_SUBJECT, $body, $headers) Send the email, reset text boxes on form, and show success message ![]() = "Content-Type: text/html charset=UTF-8\r\n" Let's dive into the script so we can get a further understanding of how it functions. This script is also self contained to a single page & has form error checking. The captcha is optional, and can be enabled/disabled at will from the configuration options. With this script, I have not only created a simple & easy to implement contact form, but I have also added a simple captcha (anti-spam) option to prevent bots from sending you unwanted email. While your actual email address is not accessible to the bot, there is nothing preventing said bot from revisiting your contact page and sending you more spam. Spambots scan the web not only for email address (ahem, mailto links anyone?) but also for contact forms with standard form names like name, email & message, from which they can automatically fill in the details and send you a message. That being said, contact forms do have their own set of issues, mainly spam. This means no ugly "mailto" links, which can cause additional user issues in the event the user does not have a mail client configured. This means that your contact form should be strait forward, easy to use, and function entirely within the website & server itself. While there are many things that all modern websites should have, one of the most important pieces to that is a functional contact page.Ī contact page is often times the portal your clients & users have to easily get in touch with you.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |