'when hitting submit the url changes to my php script location

So I am coding a simple contact form in php, and when I hit the submit button it runs the code fine on chrome on desktop, however when I hit submit on mobile browsers (and sometimes on desktop) it errors out and the url changes to the location of the script, yet it still submits an email but it being kicked back as spam when it errors out. When it does work my contact form looks fine. Can anyone spot an obvious issue I am missing?

<div class="contact_form">
  <form class="contact_form" action="contactform2.php" method="post">
    <input type="text" name="name" placeholder="Full Name..." required>
    <input type="tel" name="phone" placeholder="Phone Number..." required>
    <input type="email" name="email" placeholder="Email..." required>
    <input type="text" name="subject" placeholder="Subject..." required>
    <textarea id="message" name="message" rows="10" cols="56" placeholder="Message..." required></textarea>
    <button type="submit" name="submit">Submit</button>
  </form>
</div>

<?php

if (isset($_POST['submit'])) {
    require('phpmailer/PHPMailerAutoload.php');
    $mail = new PHPmailer;
    $mail->Host='';
    $mail->Port=587;
    $mail->SMTPAuth=true;
    $mail->SMTPSecure='tls';
    $mail->Username='';
    $mail->Password='';
    
    $mail->Setfrom($_POST['email'],$_POST['name']);
    $mail->addAddress('');
    $mail->addAddress('');
    $mail->addReplyTo($_POST['email'],$_POST['name']);
    
    $mail->isHTML(true);
    $mail->Subject=''.$_POST['subject'];
    $mail->Body='<h3 align=left>Name: '.$_POST['name'].'<br><br>Email: '.$_POST['email'].'<br><br>Telephone: '.$_POST['phone'].'<br><br>Message: '.$_POST['message'].'</h3>';
    
    if(!$mail->send()) {
        $result="Something went wrong Please try again.";
    }
    else {
        header("Location: mail_sent.html");
    }
}
?>


Solution 1:[1]

if (isset($_POST['submit']))

This is the code that checks whether the submit parameter exists.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ym y