在localhost上使用时,x-mailer邮件功能无法正常工作

I will use this code for sending simple mail. But the time of execution the condition will be false..(else part)

    $fname=$_POST['form_name'];
    $email=$_POST['form_email'];
    $phone=$_POST['form_phone'];
    $subject=$_POST['form_subject'];
    $remarks=$_POST['form_message'];


   $message = "Hi you have a new Enquiry"."
". "See Details below". "
" . "Name :".$fname." "."
". "Email :".$email. "
"."Contact Number : ".$phone."
"."Subject Number : ".$subject."
"."remarks :".$remarks."
";



        $subject='test message ' .$email;
        $message=$message;
        $headers= 'From: mail@test.in' . "
" .'Reply-To: mail@test.in' . "
" .'X-Mailer: PHP/' . phpversion();
        $headers.= 'MIME-Version: 1.0' . "
";



          if(mail("test@gmail.com",$subject,$message,$headers)) {
             echo '<div class="text-center"> <p class="success" style="color: #d1287a; font-size: 26px;
            padding-top: 30px;">Thank you for  Registering  with us, We will Contact you Soon!   </p></div>';

        } else {
            echo 'Error while sending mail,Please try again later';
        }
 }