2 Replies Latest reply on Dec 8, 2010 1:46 PM by Firefly0

    Trying to make a php file work with my email form



      Going slightly mad trying to link my php file with my html and actually getting it to work.

      It (the php file) keeps coming up with a syntax error on line 37 - code hinting may not work etc etc but there is no error from what I can see - can anyone else point out the obviously to me? This is driving me around the bend!


      my code:




      /*Subject and Email Variables */


          $emailSubject = 'Website Form';
          $webMaster = 'email@myemail.co.uk';
      /* Gathering Data Variables */
          $nameField = $_POST['name'];
          $addressField = $_POST['address'];
          $telephone1Field = $_POST['telephone1'];
          $telephone2Field = $_POST['telephone2'];
          $emailField = $_POST['email'];
          $name2Field = $_POST['name2'];
          $ageField = $_POST['age'];
          $dobField = $_POST['dob'];
          $commsField = $_POST['comms'];
          $messageField = $_POST['message'];
          $body = <<<EOD
      Name: $name <br>
      Address: $address <br>
      Telephone (daytime): $telephone1 <br>
      Telephone (mobile): $telephone2 <br>
      Email: $email <br>
      Childs Name: $name2 <br>
      Start Age: $age <br>
      Childs Date of Birth: $dob <br>
      Preferred form of communication: $comms <br>
      Message: $message <br>


          $headers = "From: $email\r\n";
          $headers .= "Content-type: text/html\r\n";
          $success = mail{$webMaster, $emailSubject,$body, $headers};
      /* Results rendered as HTML */


          $theResults = <<<EOD
      <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
      <style type="text/css">
      body {
          background-color: #f1f1f1;
          font-family: Verdana, Arial, Helvetica, sans-serif;
          font-size: 12px;
          font-style: normal;
          line-height: normal;
          font-weight: normal;
          color: #666666;
          text-decoration: none;


        <div align="left">Thank you for your message, Your email will be answered very soon!</div>
      echo "$theResults";



        • 1. Re: Trying to make a php file work with my email form
          Level 4

          Line 37 is this:


              $success = mail{$webMaster, $emailSubject,$body, $headers};


          It should be this:



              $success = mail($webMaster, $emailSubject, $body, $headers);



          Also the header for the From: is this:$headers = "From: $email\r\n"; but I don't see the variable defined for $email


          Also you should know about email injection. Someone could inject your headers and add additional BCC: addresses to send emails to many undisclosed recipients through your mail script. You'd be using your script to turn your server into a host for spam! Sanitize your fields to prevent injection attacks! Security should be the firt priority followed by functionality. If it's unsecure it shouldn't function

          • 2. Re: Trying to make a php file work with my email form
            Firefly0 Level 1

            Thank you Shocker - you've a life-saver!