Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP anti-spam contact form
Old 03-20-2008, 11:56 AM PHP anti-spam contact form
Defies a Status

Posts: 3,420
Trades: 0
I created a PHP anti-spam contact form recently and I'd like to share it with people.

The concept is that automated bots usually fill in all fields on a form so that they don't get caught out by missing required fields. This form simply hides the email address using PHP and has an extra field that is shielded from users using CSS. If this extra hidden field is filled in, then the form aborts and throws up a warning message, whilst not submitting the form. (CSS is used as opposed to the hidden HTML attribute to prevent smarter bots from missing out this field - also, the field is called an inconspicuous name that bots would not understand). Unlike other forms, it doesn't inconvenience the user at all with CAPTCHA images or anti-spam questions.

It's a little basic, but I hope people will find it useful The rest of the HTML page needs to be made (i.e. the header etc.) and the styling obviously needs to be done, but the PHP form is functional.

PHP Code:
<?php if($_POST['fred'] != "") {
    echo(
'<p style="color: #8B2323; font-size: 16px; font-weight: bold;">You may be using a text-only browser or you are a spambot. Sorry this has not been submitted</p>');    
}

else {
    if(isset(
$_POST['name'])) {

        if((
$_POST['name'] == "") or ($_POST['email'] == "") or ($_POST['message'] == "")) {
            echo(
'<p style="color: #8B2323; font-size: 16px; font-weight: bold;">Please fill in all fields</p>');
}

    else {

        
$name $_POST['name'];
        
$email $_POST['email'];
        
$company $_POST['company'];
        
$website $_POST['website'];
        
$formmessage = ($_POST['message']);
        
$emailmessage "You have received a submission from your contact form.
Name: 
$name
Email: 
$email
Company: 
$company
Website: 
$website
Message: 
$formmessage
        "
;


        
//Defining mail settings

        
$to "Enter your email address here";
        
$subject "Form submission sent";
        
$headers "From: $email";


            if(isset(
$name)) {
                
mail($to,$subject,$emailmessage,$headers);

}

}

}

}

?>
    
    <?php if(isset($name)) {
    
    echo(
'<p style="color: #8B2323; font-size: 15px; font-weight: bold;">Your submission has been sent successfully</p>');
    
    } 
?>
    
    <form action="" method="post" id="contact">
        <p><label><span>Your name: </span></label><input type="text" name="name" /><br />
        <label><span>E-mail address: </span></label><input type="text" name="email" /><br />
        <label><span>Company (optional): </span></label><input type="text" name="company" /><br />
        <label><span>Web site address (optional): </span></label><input type="text" name="website" /><br />
        <label><span>Your message: </span></label><textarea rows="15" cols="40" name="message"></textarea>
        <input type="text" id="fred" name="fred" style="visibility: hidden;"/>
        <input type="submit" value="Send" style="width: 8em; align: center;" /></p>
    </form>
Alternatively, download it from here

You can view a preview here.

Last edited by CSS4Life; 03-20-2008 at 12:23 PM..
CSS4Life is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-20-2008, 03:47 PM Re: PHP anti-spam contact form
Novice Talker

Posts: 12
Trades: 0
THanks for sharing!
__________________

Please login or register to view this content. Registration is FREE
gridsix is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP anti-spam contact form
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.09650 seconds with 12 queries