'Wordpress Form POST Request In Current Page Got Twice

I use wordpress shortcode to create a form and send post request in current page. But I will get twice post request so my mail will send twice. Hope someone can help me to fix this problem. Here is my code :

<?php 
   if(isset($_POST['flag']) && $_POST['flag'] == 'true') {            
      $message = 'MAIL CONTENT';
      $headers = array('Content-Type: text/html; charset=UTF-8');
      wp_mail(["[email protected]", "[email protected]"], 'subject', $message, $headers);
?>
      <script>
           window.setTimeout(function() {
               window.location.href = '<?=home_url()?>'+'/my-account/bookings/';
           }, 3000);
      </script>
<?php
   }else{
?>
      <div class="reupload-wrapper">
          <form action="" method="post" name="reupload" enctype="multipart/form-data">
                <input type="hidden" name="flag" value="true">
                <label for="files">File</label>
                <input type="file" class="files" name="files" id="file1" accept=".jpg, .jpeg">
                <button id="submit" type="submit" class="button">Submit</button>
          </form>
      </div>
<?php
   }
?>


Sources

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

Source: Stack Overflow

Solution Source