联系表格在同一页面上

I have a contact form below and when I submit the contact form it sends me in another page saying "Your Message was sent!", but I don't want that so I need to just display a simple message inside the contact form saying "Your Message was sent"

And I found many threads here with submit forms on the same page but still wasn't able to do this and I'm very beginner with PHP and other back end languages so if someone would help me this would appreciate a lot.

<?php 
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent= " From:  $name, 
 Email: $email 
 Message: $message";
$recipient = "myemail@gmail.com";
$subject = "New Email";
$mailheader = "From: $email 
";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
echo "Your Message was sent !";
?>
        
             <form method="POST" action="contact-form.php">      

         <input name="name" type="text" class="message" placeholder="Name" />  
 
     <input name="email" type="text" class="message" placeholder="Email"  />

  <textarea name="message" class="message" placeholder="Your Message"></textarea>

             <input type="submit" value="SUBMIT"/>

          </form>

</div>

Your code should be:

<?php 
  if(isset($_POST) && !empty($_POST)){
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $formcontent= " From:  $name, 
 Email: $email 
 Message: $message";
    $recipient = "myemail@gmail.com";
    $subject = "New Email";
    $mailheader = "From: $email 
";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
    echo "Your Message was sent !";
 }
?>
<form method="POST" action="">
  <input name="name" type="text" class="message" placeholder="Name" />  
  <input name="email" type="text" class="message" placeholder="Email"  />
  <textarea name="message" class="message" placeholder="Your Message"></textarea>
  <input type="submit" value="SUBMIT"/>
</form>

When you submit the form you have instructed it to go to "contact-form.php".

In contact-form.php you have the code to display the 'Your message was sent!' response.

If you change the action attribute to action="" and move the code from contact-form.php into the file that holds the actual contact form HTML, then providing that file is also a .php file, you should see the message appear on the page with the contact form.

It's hard without knowing the rest of your setup but essentially, that's how you'd do it.

Your Html Form File and php code file both should be same
also your form action should be call same file

Example :
File Name : contact-form.php

<?php 
if(!empty($_POST['name'])){
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];
    $formcontent= " From:  $name, 
 Email: $email 
 Message: $message";
    $recipient = "myemail@gmail.com";
    $subject = "New Email";
    $mailheader = "From: $email 
";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error");
    echo "Your Message was sent !";
}
?>
<form method="POST" action="contact-form.php">
    <input name="name" type="text" class="message" placeholder="Name" />
    <input name="email" type="text" class="message" placeholder="Email" />
    <textarea name="message" class="message" placeholder="Your Message"></textarea>
    <input type="submit" value="SUBMIT" />
</form>