<?php 
session_start();
if (!$_SESSION['loggedInUser']) {
 header("Location: login.php");
}
$resultMessage = null;
include ('db.php');
$query = "SELECT * from user";
$result = mysqli_query($connection, $query);
mysqli_close($connection);
 ?>
<!DOCTYPE html>
<html lang="en">
 <head>
 <meta charset="utf-8">
 <meta http-equiv="X-UA-Compatible" content="IE=edge">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>Client Area</title>
 </head>
 <body>
 <?php 
 // Check for Header Injections
 function has_header_injection($str) {
 return preg_match( "/[\r\n]/", $str );
 }
 $missingitemname = '<p><strong> Please Enter Item Name</p></strong>';
 if (isset($_POST['submit_form'])) {
 $itemname = $_POST["item-name"];
 $brandname = $_POST["brand"];
 $description = $_POST["description"];
 $availability = $_POST["availability"];
 $contact = $_POST["contact-p"];
 $address = $_POST["address"];
 $email = $_POST["email"];
 $location = $_POST["location"];
 $file = $_FILES["attach"];
 if (!$itemname) {
 $errors .= $missingitemname;
 } else {
 $itemname = filter_var($itemname, FILTER_SANITIZE_STRING);
 }
 if (!$email) {
 $errors .= $missingemail;
 } else {
 $email = filter_var($email, FILTER_SANITIZE_EMAIL);
 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
 $errors .= $invalidEmail;
 }
 }
 if (!$brandname) {
 $errors .= $missingbrandname;
 } else {
 $brandname = filter_var($brandname, FILTER_SANITIZE_STRING);
 }
 if ($errors) {
 $resultMessage = '<div class="alert alert-danger">'. $errors .'</div>';
}
 else {
 $to = "adamskhan123@gmail.com";
 $subject ="New Contact";
 $message ="<p>Item Name: $itemname.</p>
 <p>Brand: $brandname.</p>
 <p>Description: $description.</p>
 <p>Availability: $availability.</p>
 <p>Contact Person: $contact</p>
 <p>Email: $email</p>
 <p>Location: $location</p>
 ";
 $headers ="Content-type: text/html";
 if (mail($to, $subject, $message, $headers)) {
 $resultMessage = '<div class="alert alert-success">Thank You. Your message has been sent</div>';
 } else {
 $resultMessage = '<div class="alert alert-danger">Sorry Please Try Again.</div>';
 }
 }
}
?>
 <div class="container">
 <h1>PinTribe</h1>
 <p>Welcome <?php echo $_SESSION['loggedInUser']; ?></p>
</div>
<div class="top-content">
 <div class="inner-bg">
 <div class="container">
 <div class="row">
 <div class="col-sm-8 col-sm-offset-2 text">
 </div>
 </div>
 <div class="row">
 <div class="col-sm-6 col-sm-offset-3 form-box">
 <div class="form-top">
 <div class="form-top-left">
 </div>
 </div>
 <div class="form-bottom">
 <?php echo $resultMessage; ?>
 <form role="form" action="dashboard.php" method="post" class="login-form" enctype="multipart/form-data">
 <div class="form-group">
 <label class="sr-only" for="item-name">Item Name</label>
 <input type="text" name="item-name" placeholder="Item Name" class="username form-control" id="item-name">
 </div>
 <div class="form-group">
 <textarea type="text" name="description" placeholder="Description" class="description form-control" id="description" rows="5"></textarea>
 </div>
 <div class="form-group">
 <label class="sr-only" for="email">Email</label>
 <input type="email" name="email" placeholder="Email.." class="email form-control" id="email">
 </div>
 </div>
This is my code the problem i am getting is when I submit my form I get Sorry Please Try Again. which is failure message I added. I rechecked my code but I am not sure why I am getting this error. I filled every field but still i am not sure why it is happening. can anyone of figure it out?
 
     
     
     
    