Website Contact Form

  • spudy12
  • Born
  • Born
  • spudy12
  • Posts: 3

Post 3+ Months Ago

Hi everyone! :)
New here so please go easy on me.

I am basically trying to get a contact form on my website work.
The HTML on website looks like this
HTML
Code: [ Select ]
<form id="ContactForm" action="contactformscript.php">
                        <div class="wrapper pad_bot1">
                            <div class="wrapper">
                                <div class="bg"><input

type="text" class="input" /></div>Your Name:<br />
                            </div>
                            <div class="wrapper">
                                <div class="bg"><input

type="text" class="input" /></div>Your E-mail:<br />
                            </div>
                            <div class="wrapper">
                                <div class="bg"><div

class="textarea"><textarea name="textarea" cols="1"

rows="1"></textarea></div></div>Your Message:<br />
                            </div>
                            <div class="wrapper">
                                <a href="#"

class="button" onClick="document.getElementById('ContactForm').submit

()"><span><span>send</span></span></a>
                                <a href="#"

class="button marg_right1" onClick="document.getElementById('ContactForm').reset

()"><span><span>clear</span></span></a>
                            </div>
                        </div>
                    </form>
  1. <form id="ContactForm" action="contactformscript.php">
  2.                         <div class="wrapper pad_bot1">
  3.                             <div class="wrapper">
  4.                                 <div class="bg"><input
  5. type="text" class="input" /></div>Your Name:<br />
  6.                             </div>
  7.                             <div class="wrapper">
  8.                                 <div class="bg"><input
  9. type="text" class="input" /></div>Your E-mail:<br />
  10.                             </div>
  11.                             <div class="wrapper">
  12.                                 <div class="bg"><div
  13. class="textarea"><textarea name="textarea" cols="1"
  14. rows="1"></textarea></div></div>Your Message:<br />
  15.                             </div>
  16.                             <div class="wrapper">
  17.                                 <a href="#"
  18. class="button" onClick="document.getElementById('ContactForm').submit
  19. ()"><span><span>send</span></span></a>
  20.                                 <a href="#"
  21. class="button marg_right1" onClick="document.getElementById('ContactForm').reset
  22. ()"><span><span>clear</span></span></a>
  23.                             </div>
  24.                         </div>
  25.                     </form>


I have then linked this to the contactformsubmit.php php script.

This is the PHPscript

Code: [ Select ]
<?php
// OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!

$yourEmail = "***"; // the email address you wish to receive these mails through
$yourWebsite = "Josh Tatam PC Repairs"; // the name of your website
$thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page
$maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4
$requiredFields = "name,email,comments"; // names of the fields you'd like to be required as a minimum, separate each field with a comma


// DO NOT EDIT BELOW HERE
$error_msg = null;
$result = null;

$requiredFields = explode(",", $requiredFields);

function clean($data) {
    $data = trim(stripslashes(strip_tags($data)));
    return $data;
}
function isBot() {
    $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz");

    foreach ($bots as $bot)
        if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
            return true;

    if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
        return true;
    
    return false;
}

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (isBot() !== false)
        $error_msg .= "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT'];
        
    // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
    // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam <!-- s:) --><img src=\"{SMILIES_PATH}/icon_smile.gif\" alt=\":)\" title=\"Smile\"><!-- s:) -->
    $points = (int)0;
    
    $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "come", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "*peach*", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur", "content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript");

    foreach ($badwords as $word)
        if (
            strpos(strtolower($_POST['comments']), $word) !== false ||
            strpos(strtolower($_POST['name']), $word) !== false
        )
            $points += 2;
    
    if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)
        $points += 2;
    if (isset($_POST['nojs']))
        $points += 1;
    if (preg_match("/(<.*>)/i", $_POST['comments']))
        $points += 2;
    if (strlen($_POST['name']) < 3)
        $points += 1;
    if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))
        $points += 2;
    // end score assignments

    foreach($requiredFields as $field) {
        trim($_POST[$field]);
        
        if (!isset($_POST[$field]) || empty($_POST[$field]))
            $error_msg .= "Please fill in all the required fields and submit again.\r\n";
    }

    if (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))
        $error_msg .= "The name field must not contain special characters.\r\n";
    if (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))
        $error_msg .= "That is not a valid e-mail address.\r\n";
    if (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url']))
        $error_msg .= "Invalid website url.\r\n";
    
    if ($error_msg == NULL && $points <= $maxPoints) {
        $subject = "Contact Form @ Josh Tatam PC Repairs | Automatic Form Email";
        
        $message = "You received this e-mail message through your website: \n\n";
        foreach ($_POST as $key => $val) {
            $message .= ucwords($key) . ": " . clean($val) . "\r\n";
        }
        $message .= "\r\n";
        $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
        $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
        $message .= 'Points: '.$points;

        if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
            $headers  = "From: $yourEmail\n";
            $headers .= "Reply-To: {$_POST['email']}";
        } else {
            $headers  = "From: $yourWebsite <$yourEmail>\n";
            $headers .= "Reply-To: {$_POST['email']}";
        }

        if (mail($yourEmail,$subject,$message,$headers)) {
            if (!empty($thanksPage)) {
                header("Location: $thanksPage");
                exit;
            } else {
                $result = 'Thankyou for your query. Your mail was successfully sent and we will get back to you as soon as we can.';
                $disable = true;
            }
        } else {
            $error_msg = 'Your mail could not be sent this time. ['.$points.']';
        }
    } else {
        if (empty($error_msg))
            $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
    }
}
function get_data($var) {
    if (isset($_POST[$var]))
        echo htmlspecialchars($_POST[$var]);
}
?>
  1. <?php
  2. // OPTIONS - PLEASE CONFIGURE THESE BEFORE USE!
  3. $yourEmail = "***"; // the email address you wish to receive these mails through
  4. $yourWebsite = "Josh Tatam PC Repairs"; // the name of your website
  5. $thanksPage = ''; // URL to 'thanks for sending mail' page; leave empty to keep message on the same page
  6. $maxPoints = 4; // max points a person can hit before it refuses to submit - recommend 4
  7. $requiredFields = "name,email,comments"; // names of the fields you'd like to be required as a minimum, separate each field with a comma
  8. // DO NOT EDIT BELOW HERE
  9. $error_msg = null;
  10. $result = null;
  11. $requiredFields = explode(",", $requiredFields);
  12. function clean($data) {
  13.     $data = trim(stripslashes(strip_tags($data)));
  14.     return $data;
  15. }
  16. function isBot() {
  17.     $bots = array("Indy", "Blaiz", "Java", "libwww-perl", "Python", "OutfoxBot", "User-Agent", "PycURL", "AlphaServer", "T8Abot", "Syntryx", "WinHttp", "WebBandit", "nicebot", "Teoma", "alexa", "froogle", "inktomi", "looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory", "Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot", "crawler", "www", "Googlebot", "Scooter", "Slurp", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz");
  18.     foreach ($bots as $bot)
  19.         if (stripos($_SERVER['HTTP_USER_AGENT'], $bot) !== false)
  20.             return true;
  21.     if (empty($_SERVER['HTTP_USER_AGENT']) || $_SERVER['HTTP_USER_AGENT'] == " ")
  22.         return true;
  23.     
  24.     return false;
  25. }
  26. if ($_SERVER['REQUEST_METHOD'] == "POST") {
  27.     if (isBot() !== false)
  28.         $error_msg .= "No bots please! UA reported as: ".$_SERVER['HTTP_USER_AGENT'];
  29.         
  30.     // lets check a few things - not enough to trigger an error on their own, but worth assigning a spam score..
  31.     // score quickly adds up therefore allowing genuine users with 'accidental' score through but cutting out real spam <!-- s:) --><img src=\"{SMILIES_PATH}/icon_smile.gif\" alt=\":)\" title=\"Smile\"><!-- s:) -->
  32.     $points = (int)0;
  33.     
  34.     $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "come", "cunilingus", "cunillingus", "cunnilingus", "cunt", "ejaculate", "fag", "felatio", "fellatio", "*peach*", "fuk", "fuks", "gangbang", "gangbanged", "gangbangs", "hotsex", "hardcode", "jism", "jiz", "orgasim", "orgasims", "orgasm", "orgasms", "phonesex", "phuk", "phuq", "pussies", "pussy", "spunk", "xxx", "viagra", "phentermine", "tramadol", "adipex", "advai", "alprazolam", "ambien", "ambian", "amoxicillin", "antivert", "blackjack", "backgammon", "texas", "holdem", "poker", "carisoprodol", "ciara", "ciprofloxacin", "debt", "dating", "porn", "link=", "voyeur", "content-type", "bcc:", "cc:", "document.cookie", "onclick", "onload", "javascript");
  35.     foreach ($badwords as $word)
  36.         if (
  37.             strpos(strtolower($_POST['comments']), $word) !== false ||
  38.             strpos(strtolower($_POST['name']), $word) !== false
  39.         )
  40.             $points += 2;
  41.     
  42.     if (strpos($_POST['comments'], "http://") !== false || strpos($_POST['comments'], "www.") !== false)
  43.         $points += 2;
  44.     if (isset($_POST['nojs']))
  45.         $points += 1;
  46.     if (preg_match("/(<.*>)/i", $_POST['comments']))
  47.         $points += 2;
  48.     if (strlen($_POST['name']) < 3)
  49.         $points += 1;
  50.     if (strlen($_POST['comments']) < 15 || strlen($_POST['comments'] > 1500))
  51.         $points += 2;
  52.     // end score assignments
  53.     foreach($requiredFields as $field) {
  54.         trim($_POST[$field]);
  55.         
  56.         if (!isset($_POST[$field]) || empty($_POST[$field]))
  57.             $error_msg .= "Please fill in all the required fields and submit again.\r\n";
  58.     }
  59.     if (!preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))
  60.         $error_msg .= "The name field must not contain special characters.\r\n";
  61.     if (!preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])(([a-z0-9-])*([a-z0-9]))+' . '(\.([a-z0-9])([-a-z0-9_-])?([a-z0-9])+)+$/i', strtolower($_POST['email'])))
  62.         $error_msg .= "That is not a valid e-mail address.\r\n";
  63.     if (!empty($_POST['url']) && !preg_match('/^(http|https):\/\/(([A-Z0-9][A-Z0-9_-]*)(\.[A-Z0-9][A-Z0-9_-]*)+)(:(\d+))?\/?/i', $_POST['url']))
  64.         $error_msg .= "Invalid website url.\r\n";
  65.     
  66.     if ($error_msg == NULL && $points <= $maxPoints) {
  67.         $subject = "Contact Form @ Josh Tatam PC Repairs | Automatic Form Email";
  68.         
  69.         $message = "You received this e-mail message through your website: \n\n";
  70.         foreach ($_POST as $key => $val) {
  71.             $message .= ucwords($key) . ": " . clean($val) . "\r\n";
  72.         }
  73.         $message .= "\r\n";
  74.         $message .= 'IP: '.$_SERVER['REMOTE_ADDR']."\r\n";
  75.         $message .= 'Browser: '.$_SERVER['HTTP_USER_AGENT']."\r\n";
  76.         $message .= 'Points: '.$points;
  77.         if (strstr($_SERVER['SERVER_SOFTWARE'], "Win")) {
  78.             $headers  = "From: $yourEmail\n";
  79.             $headers .= "Reply-To: {$_POST['email']}";
  80.         } else {
  81.             $headers  = "From: $yourWebsite <$yourEmail>\n";
  82.             $headers .= "Reply-To: {$_POST['email']}";
  83.         }
  84.         if (mail($yourEmail,$subject,$message,$headers)) {
  85.             if (!empty($thanksPage)) {
  86.                 header("Location: $thanksPage");
  87.                 exit;
  88.             } else {
  89.                 $result = 'Thankyou for your query. Your mail was successfully sent and we will get back to you as soon as we can.';
  90.                 $disable = true;
  91.             }
  92.         } else {
  93.             $error_msg = 'Your mail could not be sent this time. ['.$points.']';
  94.         }
  95.     } else {
  96.         if (empty($error_msg))
  97.             $error_msg = 'Your mail looks too much like spam, and could not be sent this time. ['.$points.']';
  98.     }
  99. }
  100. function get_data($var) {
  101.     if (isset($_POST[$var]))
  102.         echo htmlspecialchars($_POST[$var]);
  103. }
  104. ?>


I realize i haven't properly set the onclick actions but I'm not really sure how to as i'm quite new to this, but am very willing to learn!
If anyone can direct me o, or give me some instructions on what I should point the HTML to in the PHP script i would much appreciate it!


many thanks
Spud
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

You need name="" in the input...

<input type="text" class="input" name="name" />

And name="email" for the email and name="comments" for the textarea (The message).
  • spudy12
  • Born
  • Born
  • spudy12
  • Posts: 3

Post 3+ Months Ago

Hi there, thankyou for the quick response!

I have tried what you said, and added the name="" fields (which makes sense.. durrr silly me)

The only problem is now it doesn't seem to send the email?
I added the link to the thanks page on the onClick action, which takes the user to that page. It just doesn't seem to the send the email.

(P.s I have added the email address on the script in replace of *****, it just wouldn't let me post links here as i'm new!)

I cant seem to find anywhere where errors would be posted i.e a log?

What should I do now?
Many thanks
Spud
  • spudy12
  • Born
  • Born
  • spudy12
  • Posts: 3

Post 3+ Months Ago

Okay, so i have realised where i was going wrong. The script I was using was a php script and the webpage was set up for a ASP script. Doh

Okay, well using the input form that came with the php script it looks like this
joshtatam.c(o.u)k/Contact-test.html

I want it to look like this
joshtatam.c(o.u)k/Contact.html

Every way i have tried results in the script breaking or the tables it look stupid (sorry I am a perfectionist.)

any help would be greatly appreciated :)

Many thanks

Spud
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8388
  • Loc: USA

Post 3+ Months Ago

Ok, going on that site it took me a little bit of time to find the actual form. I would recommend putting a black border around the fields.

And for the name of the page you should be able to just name it contact.html and it should work fine (unless that page has PHP script written in it in which case you would need to name it contact.php).


And for the Submit link you can have it as a submit button and style it to look like a link... that gets rid of javascript.

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 41 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.