SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    0 Post(s)
    0 Thread(s)

    Contactform with Honeypot (+ loadtime function)

    Hey guys,

    I'm new and have read (and tried) all posts about honeypots for my contactform.
    I have also tried a combination with a loadtime function, but that also failed.
    In my example below I have only the honeypot function, but it's not working...

    Which PHP-guru can help me out? I asume only the PHP part is wrong....
    I also asume I only have to adjust the "sendemail.php" and not the "class.sendemail.php".

    Who can help me out? Score extra points by also putting a loadtime function in it ;-)

    Thanks for all your help!
    HTML Code:
    CSS (style.css):
    .robotic {
    HMTL (index.html):
                        <div id="contactform">    
                            <div id="response"></div>
                            <form method="POST" action="sendemail.php" class="form">
                                <div id="main">
                                                  <p class="name">
                                        <input type="text" name="name" id="name" />
                                        <label for="name" class="overlabel">Name</label>
                                    <p class="email">
                                        <input type="text" name="email" id="email" />
                                        <label for="email" class="overlabel">E-mail</label>
                                    <p class="text">
                                        <textarea name="comments" id="comments" ></textarea>
                                        <label for="comments" class="overlabel">Comments</label>
                                                                                                                    <!-- Honeypot -->
                                                                                                                    <p class="robotic" id="pot">
                                                                                                                                  <input type="text" name="robotest" id="robotest" />
                                        <label for="robotest" class="overlabel">Leave this blank</label>
                                    <p class="submit">
                                        <button type="submit" name="submit" id="submit" class="graybutton">Send e-mail</button>
                                </div><!--end main-->
                        </div><!--end contact form-->

    PHP (sendemail.php):
    PHP Code:
    $email $_POST['email'];
    $comments $_POST['comments'];
    $robotest $_POST['robotest'];
    $site_owners_email ''
    $site_owners_name 'Xxx Xxx'

        if (
    strlen($name) < 2) {
    $error['name'] = "Enter your name";    
        if (!
    preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is'$email)) {
    $error['email'] = "Enter a valid e-mail";    
        if (
    strlen($comments) < 3) {
    $error['comments'] = "Leave a comment";

        if (
    strlen($robotest) > 2) {
    $error['robotest'] = "You are a bot";

        if (!
    $error) {

    $mail = new PHPMailer();
    $mail->From $email;
    $mail->FromName $name;
    $mail->Subject "Bericht via de website";
    $mail->Body $comments;
    "<p class='success'> Message sent </p>";
    # end if no error
    else {

    $response = (isset($error['name'])) ? "<p id='error1'>" $error['name'] . " \n" null;
    $response .= (isset($error['email'])) ? "<p id='error2'>" $error['email'] . "</p> \n" null;
    $response .= (isset($error['comments'])) ? "<p id='error3'>" $error['comments'] . "</p>" null;
    $response .= (isset($error['robotest'])) ? "<p id='error4'>" $error['robotest'] . "</p>" null;
    # end if there was an error sending

    Last edited by ServerStorm; Jan 11, 2013 at 15:30. Reason: Added code tags


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts