Create a PHP file like mail.php. In the form you will direct to that file.
<form action="mail.php" method="post">
In the mail.php you will verify the inputs:
$username = isset($_POST["username"]) ? $_POST["username"] : "";
It means that if username is actually set then $username
will get that value, the empty string otherwise.
Using the ternary operator. You should do this for all the inputs.
If you don't want to use the ternary operator (which I highly recommend though) then you can do this instead:
if(isset($_POST["username"]))
{
$username = $_POST["username"];
}
else
{
$username = "";
}
If you're satisfied with all the inputs then you can use the built in mail function to send the email.
Once completed you can redirect the user back:
header("Location: index.php");
I've answered a similar question before which you can feel free to look at, there are also plenty of resources on the internet that will help you.