php form issue?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mikeinspain
    New Member
    • Jan 2007
    • 21

    php form issue?

    hi there..

    I have a php form script that is pretty much there... I am however having a problem when I go to test the form. the mail comes through into my inbox displaying the information ok apart from the tel no.. field.. where it displays the entered email address.

    the code is below.. any help appreciated... :-)

    [PHP]<?php
    if (isset($_POST["op"]) && ($_POST["op"]=="send")) {

    /******** START OF CONFIG SECTION *******/
    $sendto = "admin@cbweb.co .uk";
    $subject = "Website Contact Enquiry | General Enquiry";
    // Select if you want to check form for standard spam text
    $SpamCheck = "Y"; // Y or N
    $SpamReplaceTex t = "*content removed*";
    // Error message prited if spam form attack found
    $SpamErrorMessa ge = "<p align=\"center\ "><font color=\"red\">M alicious code content detected.
    </font><br><b>You r IP Number of <b>".getenv("RE MOTE_ADDR")."</b> has been logged.</b></p>";
    /******** END OF CONFIG SECTION *******/


    $name = $HTTP_POST_VARS['name'];
    $email = $HTTP_POST_VARS['email'];
    $tel = $HTTP_POST_VARS['email'];
    $message = $HTTP_POST_VARS['message'];
    $headers = "From: $email\n";
    $headers . "MIME-Version: 1.0\n"
    . "Content-Transfer-Encoding: 7bit\n"
    . "Content-type: text/html; charset = \"iso-8859-1\";\n\n";
    if ($SpamCheck == "Y") {
    // Check for Website URL's in the form input boxes as if we block website URLs from the form,
    // then this will stop the spammers wastignt ime sending emails
    if (preg_match("/http/i", "$name")) {echo "$SpamErrorMess age"; exit();}
    if (preg_match("/http/i", "$email")) {echo "$SpamErrorMess age"; exit();}
    if (preg_match("/http/i", "$tel")) {echo "$SpamErrorMess age"; exit();}
    if (preg_match("/http/i", "$message") ) {echo "$SpamErrorMess age"; exit();}

    // Patterm match search to strip out the invalid charcaters, this prevents the mail injection spammer
    $pattern = '/(;|\||`|>|<|&|^ |"|'."\n|\r|'". '|{|}|[|]|\)|\()/i'; // build the pattern match string

    $name = preg_replace($p attern, "", $name);
    $email = preg_replace($p attern, "", $email);
    $tel = preg_replace($p attern, "", $tel);
    $message = preg_replace($p attern, "", $message);

    // Check for the injected headers from the spammer attempt
    // This will replace the injection attempt text with the string you have set in the above config section
    $find = array("/bcc\:/i","/Content\-Type\:/i","/cc\:/i","/to\:/i");
    $tel = preg_replace($f ind, "$SpamReplaceTe xt", $tel);
    $email = preg_replace($f ind, "$SpamReplaceTe xt", $email);
    $name = preg_replace($f ind, "$SpamReplaceTe xt", $name);
    $message = preg_replace($f ind, "$SpamReplaceTe xt", $message);

    // Check to see if the fields contain any content we want to ban
    if(stristr($nam e, $SpamReplaceTex t) !== FALSE) {echo "$SpamErrorMess age"; exit();}
    if(stristr($mes sage, $SpamReplaceTex t) !== FALSE) {echo "$SpamErrorMess age"; exit();}

    // Do a check on the send email and subject text
    if(stristr($sen dto, $SpamReplaceTex t) !== FALSE) {echo "$SpamErrorMess age"; exit();}
    if(stristr($sub ject, $SpamReplaceTex t) !== FALSE) {echo "$SpamErrorMess age"; exit();}
    }
    // Build the email body text
    $emailcontent = "
    -----------------------------------------------------------------------------
    WEBSITE CONTACT ENQUIRY | GENERAL ENQUIRY
    -----------------------------------------------------------------------------

    Name: $name

    Email: $email

    Tel No: $tel

    Message: $message

    _______________ _______________ _________
    End of Email
    ";
    // Check the email address enmtered matches the standard email address format
    if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$", $email)) {
    echo "<p>It appears you entered an invalid email address</p><p><a href='javascrip t: history.go(-1)'>Click here to go back</a>.</p>";
    }

    elseif (!trim($name)) {
    echo "<p>Please go back and enter a Name</p><p><a href='javascrip t: history.go(-1)'>Click here to go back</a>.</p>";
    }

    elseif (!trim($message )) {
    echo "<p>Please go back and type a Message</p><p><a href='javascrip t: history.go(-1)'>Click here to go back</a>.</p>";
    }

    elseif (!trim($email)) {
    echo "<p>Please go back and enter an Email</p><p><a href='javascrip t: history.go(-1)'>Click here to go back</a>.</p>";
    }

    elseif (!trim($tel)) {
    echo "<p>Please go back and enter an Telephone Number</p><p><a href='javascrip t: history.go(-1)'>Click here to go back</a>.</p>";
    }


    // Sends out the email or will output the error message
    elseif (mail($sendto, $subject, $emailcontent, $headers)) {
    echo "<br><br><p><b> Thank You $name</b></p><p>We will be in touch as soon as possible.</p>";

    }
    }
    else {
    ?> [/PHP]

    Cheers

    Mike
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    $tel = $HTTP_POST_VARS['email'];

    Im betting this is your problem :)

    Btw.

    The $HTTP_POST_VARS['varname'] is kind of a overkill dont you think?

    I mean you could use $_POST['varname'] or even just $varname

    Comment

    • mikeinspain
      New Member
      • Jan 2007
      • 21

      #3
      Will give that a go thanks..

      Mike

      :-)

      Comment

      • mikeinspain
        New Member
        • Jan 2007
        • 21

        #4
        That has done the trick.. Thanks again!!

        Comment

        Working...