title: Basic php form handling security questions
body: <p>Very new to PHP, making a web form that posts its contents to a PHP file. PHP file needs to bundle the data into an email to myself as I am not confident enough to send the data directly into our system. I uploaded a test PHP file to the server to test and over the weekend I have received a number of blank emails sent by the file, I assume this means someone is accessing the file without completing the form. </p>
  
  <ol>
  <li>Am I using the correct if statement to prevent the code running when someone navigates to my php file?</li>
  <li>How can I make the .php inaccessible to anyone but the webform?</li>
  <li><p>Have I made any glaring errors?</p>
  
  <pre><code>&lt;?php 
  if($_SERVER["REQUEST_METHOD"] == "POST") {
  $emailbody = 'Name: '.$_POST['m_title'].' '.$_POST['m_firstname'].' '.$_POST['m_surname']."\n"
              .'Email: '.$_POST['m_email']."\n"
              .'Phone: '.$_POST['m_phone']."\n"
              .'D.O.B: '.$_POST['m_dob_day'].' '.$_POST['m_dob_month'].' '.$_POST['m_dob_year']."\n"          
              .'Postcode: '.$_POST['m_postcode']."\n"
              .'Lenders: '.$_POST['m_bank1'].','.$_POST['m_bank2'].','.$_POST['m_bank3'].','.$_POST['m_bank4'].','.$_POST['m_bank5'].','.$_POST['m_bank6'].','.$_POST['m_bank7'].','.$_POST['m_bank8'];
  mail('**removed**', 'Web Lead', $emailbody);
  header('Location: https://www.**removed**' true, 301);
  }
  exit();
  </code></pre>
  
  <p>?></p></li>
  </ol>