Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4

Thread: PHP form help

  1. #1
    Junior Member
    Join Date
    May 2015
    Posts
    2
    Member #
    49716

    PHP form help

    Hello lovely people!

    I have created a form in HTLM and wish to output the results of it to my email.

    Now I have created a PHP file to do this, but it just doesnt work, could anyone have a little look at it for me?

    When I click submit on the form itself, it just opens up a blank PHP page instead of sending me an email, any thoughts?

    Heres there code...

    <?php


    $yourEmail = "ianjeff22@gmail.com";
    $yourWebsite = "http://www.oakroadtiddington.co.uk/";
    $thanksPage = '/thankyou.html';
    $maxPoints = 4;
    $requiredFields = "comments";



    $error_msg = array();
    $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.galaxy.com", "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'];


    $points = (int)0;

    $badwords = array("adult", "beastial", "bestial", "blowjob", "clit", "cum", "cunilingus", "cunillingus", "cunnilingus", "****", "ejaculate", "fag", "felatio", "fellatio", "****", "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;
    if (preg_match("/[bcdfghjklmnpqrstvwxyz]{7,}/i", $_POST['comments']))
    $points += 1;


    foreach($requiredFields as $field) {
    trim($_POST[$field]);

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

    if (!empty($_POST['name']) && !preg_match("/^[a-zA-Z-'\s]*$/", stripslashes($_POST['name'])))
    $error_msg[] = "The name field must not contain special characters.\r\n";
    if (!empty($_POST['email']) && !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 = "Automatic Form Email";

    $message = "You received this e-mail message through your website: \n\n";
    foreach ($_POST as $key => $val) {
    if (is_array($val)) {
    foreach ($val as $subval) {
    $message .= ucwords($key) . ": " . clean($subval) . "\r\n";
    }
    } else {
    $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\r\n";
    } else {
    $headers = "From: $yourWebsite <$yourEmail>\r\n";
    }
    $headers .= "Reply-To: {$_POST['email']}\r\n";

    if (mail($yourEmail,$subject,$message,$headers)) {
    if (!empty($thanksPage)) {
    header("Location: $thanksPage");
    exit;
    } else {
    $result = 'Your mail was successfully sent.';
    $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]);
    }
    ?>

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,686
    Member #
    5580
    Liked
    716 times
    Blank because you have errors, but error reporting is not turned on ...

    Put this at top of script and run it again ...

    <?php
    error_reporting
    (E_ALL);





  4. #3
    Junior Member
    Join Date
    May 2015
    Posts
    2
    Member #
    49716
    You are an absolute LEGEND!!! Ran the error reporting, sorted out errors and now its working Thanks so so much!

  5. #4
    Junior Member
    Join Date
    May 2015
    Posts
    11
    Member #
    49734
    <?php
    error_reporting()


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 05:07 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com