I built a simple form for suggestions from visitors to our website. It allows users to choose whether or not to include a name or email address. If they enter nothing at all (or the email is invalid) I simply insert "anonymous".

If I enter garbage or nothing at all into the email field, the email is properly sent using "anonymous". If, however, I enter a valid email address then no email is sent. I must have gone over this a hundred times and I just cannot find the error. Any guidance would be greatly appreciated. Thanks.

HTML Code:
<form id="contact" method="post">
              <fieldset> 
                <textarea rows="3" name="text" id="text" placeholder="Enter your comments here"></textarea>
                <div class="formgroup">
                <label>Name (optional):</label>
                <input name="name" id="name" type="text" placeholder="Name">
                </div>
                </br>
                <div class="formgroup">  
                <label>Email (required if you would like a response):</label>
                <input name="email" id="email" type="text" placeholder="Email address"> 
                </div>
              </fieldset>
              <p id="errortext" class="error_text">The comment field is empty. Please enter your comments.</p>
              <input type="submit" value="Send Message" name="submit" class="btn btn-secondary-dk" >
            </form>


<script type="text/javascript">
	$("#contact").submit(function(e){
	  e.preventDefault();
	  var text = $("#text").val();
	  var name = $("#name").val();
	  var email = $("#email2").val();
	  if(!name){
		name = "anonymous";
	  };  
  
	  var dataString = 'name=' + name + '&text=' + encodeURIComponent(text) + '&email=' + email;
	  
	  if (text.length > 10){
	    document.getElementById('errortext').style.display = "none";
		$.ajax({
		type: "POST",
		url: "libs/contact.php",
		data: dataString,
		success: function(e){
		  	$('#basic-modal-content').modal();
			return false;
		}
		});
	  } else if (text.length < 10) {
		$('.error_text').fadeIn(1000);
	  };
	 
	  return false;
	});
</script>
And this PHP:

PHP Code:
// Email Submit
// Note: filter_var() requires PHP >= 5.2.0

if ($_POST["email"] = "" || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
  
$_POST["email"] = "anonymous@anonymous.com";
}

if ( isset(
$_POST['email']) && isset($_POST['name']) && isset($_POST['text']) && filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ) {
 
  
// detect & prevent header injections
  
$test "/(content-type|bcc:|cc:|to:)/i";
  foreach ( 
$_POST as $key => $val ) {
    if ( 
preg_match$test$val ) ) {
      exit;
    }
  }
  
echo 
$_POST['email'];
  
  
//send email
  
mail"janedoe@url.com""Website suggestions from: ".$_POST['name'], $_POST['text'], "From:" $_POST['email'] );