sunaruna84 0 Newbie Poster

Hi friends
I have using this mail function in usermail.php. my problem is some times i didn't receive the mail and displayed mail not sent alert when i submit the enquiry form. please verify it and let me know ur suggestion. please help me this function will be work in session based.

<?php
if(isset($_POST['name'])&&($_POST['companyname'])&&($_POST['address'])&&($_POST['country'])&&
($_POST['email'])&&($_POST['phone'])&&($_POST['enquiry'])&&($_POST['details'])){

echo"test1";
$msg = "<b>Name</b> : ". $_POST['name'] . "<br><b>Company Name</b> : " . $_POST['companyname'] . "<br><b>Address</b> : " . $_POST['address']."<br><b>Country</b>:".$_POST['country']."<br><b>Email</b>:".$_POST['email']."<br><b>Phone</b>:".$_POST['phone']."<br><b>Enquiry for</b>:".$_POST['enquiry']."<br><b>Details</b>:".$_POST['details'];
$mailSent = sendMail("sunaruna84@gmail.com",$_POST['name'],$_POST['email'],$msg,"Enquiry Details");
}
function sendMail($to,$fromname,$fromemail,$msg,$subject){
echo"test3";
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: ".$fromname." <".$fromemail.">\r\n";
$msg = stripslashes($msg);
if(mail($to,$subject,$msg,$headers)){
echo"test4";
echo '<script type="text/javascript">';
echo "alert('Enquiry posted successfully')";
echo "</script>";
echo "<p><a href='enquiry.php'>click here</a> to go back....</p>";
}
else{
echo"test5";
echo '<script type="text/javascript">';
echo "alert('Mail has not been succesfully passed to us.. sorry ...')";
echo "</script>";
echo "<p><a href='enquiry.php'>click here</a> to go back....</p>";
}

}
?>