Reviews on a contact-us form I tried my hand at a contact-us PHP script. I came up with the following. First the markup, then a little client-side validation and then the email script. I just need to know if this is usable code. 
I actually got to the point where I can make some cash developing websites. I just need to know if this is valid
HTML


function validateContactForm() {
  var valid = true;

  $(".info").html("");
  $(".input-field").css('border', '#e0dfdf 1px solid');
  var userName = $("#userName").val();
  var userEmail = $("#userEmail").val();
  var subject = $("#subject").val();
  var content = $("#content").val();

  if (userName == "") {
    $("#userName-info").html("Required.");
    $("#userName").css('border', '#e66262 1px solid');
    valid = false;
  }
  if (userEmail == "") {
    $("#userEmail-info").html("Required.");
    $("#userEmail").css('border', '#e66262 1px solid');
    valid = false;
  }
  if (!userEmail.match(/^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/)) {
    $("#userEmail-info").html("Invalid Email Address.");
    $("#userEmail").css('border', '#e66262 1px solid');
    valid = false;
  }

  if (subject == "") {
    $("#subject-info").html("Required.");
    $("#subject").css('border', '#e66262 1px solid');
    valid = false;
  }
  if (content == "") {
    $("#userMessage-info").html("Required.");
    $("#content").css('border', '#e66262 1px solid');
    valid = false;
  }
  return valid;
}
&lt;form name="frmContact" id="frmContact" method="post" action="" enctype="multipart/form-data" onsubmit="return validateContactForm()"&gt;

  &lt;div class="input-row"&gt;
    &lt;label style="padding-top: 20px;"&gt;Name&lt;/label&gt; &lt;span id="userName-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;input type="text" class="input-field" name="userName" id="userName" /&gt;
  &lt;/div&gt;
  &lt;div class="input-row"&gt;
    &lt;label&gt;Email&lt;/label&gt; &lt;span id="userEmail-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt; &lt;input type="text" class="input-field" name="userEmail" id="userEmail" /&gt;
  &lt;/div&gt;
  &lt;div class="input-row"&gt;
    &lt;label&gt;Subject&lt;/label&gt; &lt;span id="subject-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt; &lt;input type="text" class="input-field" name="subject" id="subject" /&gt;
  &lt;/div&gt;
  &lt;div class="input-row"&gt;
    &lt;label&gt;Message&lt;/label&gt; &lt;span id="userMessage-info" class="info"&gt;&lt;/span&gt;&lt;br /&gt;
    &lt;textarea name="content" id="content" class="input-field" cols="60" rows="6"&gt;&lt;/textarea&gt;
  &lt;/div&gt;
  &lt;div&gt;
    &lt;input type="submit" name="send" class="btn-submit" value="Send" /&gt;

    &lt;div id="statusMessage"&gt;
      &lt;?php if (!empty($message)) { ?&gt;
      &lt;p class='&lt;?php echo $type; ?&gt;Message'&gt;
        &lt;?php echo $message; ?&gt;
      &lt;/p&gt;
      &lt;?php } ?&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/form&gt;



PHP
&lt;?php if (!empty($_POST['send'])) {
    $name = $_POST['userName'];
    $email = $_POST['userEmail'];
    $subject = $_POST['subject'];
    $content = $_POST['content'];

    $toEmail = 'neilmeyermusic@gmail.com';
    $mailHeaders = 'From: ' . $name . '&lt;' . $email . &quot;&gt;\r\n&quot;;
    if (mail($toEmail, $subject, $content, $mailHeaders)) {
        $message = 'Your contact information is received successfully.';
        $type = 'success';
    }
}
require_once &quot;contact-view.php&quot;;
?&gt;
The script is extremely basic but it seems to me that it is also not secure. I have seen similar code that vulnerable to header injection, so it was possible for spammers to add a BCC header, and instead spam other people through your server (and your IP address will get blacklisted as a result).
Even a seasoned class like phpmailer has suffered nasty security bugs. Another article that touches on the issue: Why mail() is dangerous in PHP
Since $mailHeaders is injectable, I can provide an E-mail address like:
someone@attacker.com@\r\nBcc: someone@victim.com
and I should be able to send spam to someone@victim.com, with your unwitting assistance.
Validation of form fields in Javascript is not sufficient, it has to be performed server-side as well. Javascript is useful for instant, client-side validation to avoid back and forth exchanges with the server but cannot be considered a security feature since you don't control the client and can't trust it.
It is only a matter of time until your form is indexed by spambots, that will start pounding your server. The bots don't care about Javascript. Your script will not stop them. So basically everything you wrote in JS has to be implemented server-side in PHP. JS validation is nice to have but optional.
Since it appears that you are using Bootstrap, you could perhaps take advantage of the validation options available. Then you can also get rid of the inline CSS styling eg: $(&quot;#userEmail&quot;).css('border', '#e66262 1px solid');.
You can also use the required attribute in your mandatory HTML controls. Then the browser will prompt the user if some fields are empty, and will not submit the form. It is a small extra and costs nothing.
To sum up, I suggest that you read up a bit on header injection and don't reinvent the wheel. There is mature, open-source third-party code available for this kind of task. It will be more secure that your homemade attempt.
I seem to remember that there is also the possibility of nullbyte injection but can't remember the details right now.