I'm aware there are other posts on this topic but none of the few solutions provided have worked for me.
I'm using an HTML form to execute some PHP code to send an email. On clicking the submit button though I'm redirected to a new page and I need to prevent this.
Here's my HTML code:
<form method="post" name="myemailform" action="send-email.php">
<input type="text" required placeholder="Name" size="19" name="name" style="width: 15vw"><br><br>
<input type="email" required placeholder="Email" name="email" style="width: 15vw"><br><br>
<textarea type="text" required placeholder="Message" name="message" style="width: 25vw; height: 15vh; resize: none"></textarea>
<br><br>
<button onclick="change()" type="submit" value="Submit" id="send_button">SEND</button>
</form>
And my PHP code:
<?php
$name = $POST['name'];
$visitor_email = $POST['email'];
$message = $POST['message'];
$email_from = 'my email';
$email_subject = "***Email from Personal Website";
$email_body = "You have received a new message from $name.\n".
"Here is the message:\n $message \n".
$to = "my email";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to,$email_subject,$email_body,$headers);
?>