contact form help

Discussion in 'PHP' started by danny322, Nov 22, 2007.

  1. #1
    Hi people, im new to php but i have to make a contact form. You can see the page at.... http://www.geneticsweb.co.uk/contact.php im having problems getting it working as you can probably see and i dont know how to fix it or where to start. Any help would be appreciated.

    Thankyou

    
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    if(isset($_POST['submit'])) { 
    $to = "danielm@design365.co.uk"; 
    $subject = "Genetics Feedback"; 
    $name_field = $_POST['name'];
    $telephone_field = $_POST['telephone']; 
    $email_field = $_POST['email']; 
    $comments_field = $_POST['comments']; 
    $message = $_GET['message'];
     
    $body = "From: $name_field\n E-Mail: $telephone_field\n Telephone: $email_field\n Comments:\n $comments"; 
     
     
    if(mail($to, $subject, $body)) { 
    $message = "Sent!";}
    else { echo "Mail failed"; } 
     
    function antispam()
    {
    // First, make sure the form was posted from a browser.
    // For basic web-forms, we don't care about anything
    // other than requests from a browser:
        if (!isset($_SERVER['HTTP_USER_AGENT'])) {
            die("Forbidden - You are not authorized to view this page");
            exit;
        }
    // Make sure the form was indeed POST'ed:
        //  (requires your html form to use: action="post")
        if (!$_SERVER['REQUEST_METHOD'] == "POST") {
            die("Forbidden - You are not authorized to view this page");
            exit;
        }
    // Make sure the form was posted from an approved host name.
        if (!strstr($_SERVER['HTTP_REFERER'], "cashincar")) {
            //logBadRequest();
            header("HTTP/1.0 403 Forbidden");
            exit;
        }
    // Attempt to defend against header injections:
        $badStrings = array("Content-Type:",
        "MIME-Version:",
        "Content-Transfer-Encoding:",
        "bcc:",
        "cc:",
        "http://www.genetics.co.uk/contact.php");
    // Loop through each POST'ed value and test if it contains
        // one of the $badStrings:
        foreach($_POST as $k => $v){
            foreach($badStrings as $v2){
                if (strpos($v, $v2) !== false) {
                    //        logBadRequest();
                    header("HTTP/1.0 403 Forbidden");
                    exit;
                }
            }
     
        }
     
    }
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>geNetics Web - Next Generation Web Development</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <link rel="stylesheet" type="text/css" href="gen.css">
    </head>
    <body>
    <div id="wrapper">
      <div id="about_us">
        <ul>
          <li><a href="index.html"> Home</a></li>
          <li><a href="our_team.html">Our team</a></li>
          <li><a href="about_us.html">About us</a></li>
          <li><a href="our_work.html">Our work</a></li>
          <li><a href="contact.php"class="yourhere">Contact</a></li>
        </ul>
     
     
     
     <p>Please don't hesitate to contact us, we will be more than happy to help. Simply fill out the form below:</p>
    <div class="form"><form name="contact" action="contact.php" method="POST">
      Your Name:<br>
      <input class="form_style" name="name" type="text" size="20" maxlength="30"/><br><br>
      Telephone:<br>
      <input class="form_style" name="telephone" type="text" size="20" maxlength="20" /><br><br>
      Email:<br>
      <input class="form_style" name="email" type="text" size="20" maxlength="50" /><br><br>
      Comments and Questions:<br>
         <textarea class="form_style" name="comments" cols="20" rows="5"></textarea><br>
       <input class="submitbtn" name="submit" type="submit" value="Submit"/>
       </form>
       <?php echo $message ; ?>
       </div>
    </div>
     
      <div id="footer">Next generation web development</div> 
    </body>
    </html>
    
    Code (markup):
     
    danny322, Nov 22, 2007 IP
  2. chandubhai

    chandubhai Banned

    Messages:
    556
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Whats the error you are getting?
     
    chandubhai, Nov 22, 2007 IP
  3. kreoton

    kreoton Peon

    Messages:
    229
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    first if end braked is missing. may you describe what your problem is?
     
    kreoton, Nov 22, 2007 IP
  4. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #4
    Barti1987, Nov 22, 2007 IP
  5. triphp123

    triphp123 Well-Known Member

    Messages:
    1,491
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    125
    #5
    triphp123, Nov 22, 2007 IP
  6. SEOWOES

    SEOWOES Peon

    Messages:
    60
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    SEOWOES, Nov 22, 2007 IP