代码总是转到else循环并发送错误消息.代码是错的吗?


The code always goes to the else loop and sends the error message. Is the code wrong?

<?php
 if(isset($_POST['submit']))
 {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $query = $_POST['message'];
    $email_from = $name.'<'.$email.'>';
    $to="someone@gmail.com";
    $subject="Enquiry!";
    $headers .= "From: ".$email_from."'r'n";
    $headers  = 'MIME-Version: 1.0' . "'r'n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n".PHP_EOL;
    $message="mail sent";

    if(mail($to,$subject,$message,$headers))
    {
        header("Location:../contact.php?msg=Successful Submission! Thankyou for contacting us.");
    }
    else
    {
        header("Location:../contact.php?msg=Error To send Email !");
    }
}
?>
<?php
 if(isset($_POST['submit']))
 {
    $name = $_POST['name'];
    $email = $_POST['email'];
    $query = $_POST['message'];
    $email_from = $name."<'.$email.'>"; //Check Properly Here
    $to="someone@gmail.com";
    $subject="Enquiry!";
    $headers .= "From: ".$email_from."'r'n";
    $headers  = 'MIME-Version: 1.0' . "'r'n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "'r'n".PHP_EOL;
    $message="mail sent";
    $SendMail=mail($to,$subject,$message,$headers); //Check Here Too
    if($SendMail)
    {
        header("Location:../contact.php?msg=Successful Submission! Thankyou for contacting us.");
    }
    else
    {
        header("Location:../contact.php?msg=Error To send Email !");
    }
}
?>