So I have this form in my HTML page and I linked it to an external PHP file (form.php). What I want is that after the user enters his or her details and hits the submit button the website to send me that info via email. This is the code I used:
<form action="/form.php" method="POST">
<label for="first_name">First name</label>
<input type="text" name="first_name" required>
<label for="last_name">Last Name</label>
<input type="text" name="last_name" required>
<label for="email">Email</label>
<input type="email" name="email" required>
<label for="phone">Phone</label>
<input type="tel" name="phone" maxlength="10">
<label for="comments">Comments</label>
<input type="text" id="comments" name="comments">
<input type="submit" id="submit">
</form>
<?php
$userName = $_POST['first_name'];
$userLastname = $_POST['last_name'];
$userEmail = $_POST['email'];
$userPhone = $_POST['phone'];
$userComments = $_POST['comments'];
$to = "danieltomaalexandru@gmail.com";
$subject = "New Message";
$body = "";
$body .= "From: ".$userName. .$userLastname. "\r\n";
$body .= "Email: ".$userEmail. "\r\n";
$body .= "Phone: ".$userPhone. "\r\n";
$body .= "Message: ".$userComments. "\r\n";
mail($to,$subject,$body);?>
The problem is that when I click submit it gives an error saying that the website is unable to handle the request HHTP error 500