title: Stopping empty form submission PHP
body: <p>I have been trying to implement server validation to prevent blank emails in my contact us page, but I am not sure on how to do it in PHP, here is my code:</p>
  
  <pre><code>&lt;?php
  $field_name = $_POST['cf_name'];
  $field_email = $_POST['cf_email'];
  $field_tel = $_POST['cf_tel'];
  $field_message = $_POST['cf_message'];
  
  
  $mail_to = 'test@test.com, test@test.com, test@test.com';
  $subject = 'Just iStuff Mobile Contact Us: '.$field_name;
  
  $body_message = 'From: '.$field_name."\n";
  $body_message .= 'E-mail: '.$field_email."\n";
  $body_message .= 'Telephone Number: '.$field_tel."\n";
  $body_message .= 'Message: '.$field_message;
  
  $headers = 'From: '.$field_email."\r\n";
  $headers .= 'Reply-To: '.$field_email."\r\n";
  
  $mail_status = mail($mail_to, $subject, $body_message, $headers);
  
  if ($mail_status) { ?&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          alert('Thank you for your email, we have received your message and will reply within the next few days.');
          window.location = 'contactus.html';
      &lt;/script&gt;
  &lt;?php
  }
  else { ?&gt;
      &lt;script language="javascript" type="text/javascript"&gt;
          alert('Message failed, please try again or email test@test.com');
          window.location = 'contactus.html';
      &lt;/script&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>
  
  <p>Can anyone help me to do this, the tutorials online do not cover this way of doing it...</p>
  
  <p>Thanks</p>