0

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

Alex Toma
  • 35
  • 5
  • A 500 error is a generic error message and covers pretty much every single thing that can go wrong with a PHP script. Check your server error logs to find out the exact error message. – aynber Oct 27 '21 at 15:52
  • `.$userName. .$userLastname.` You have a double period here. Did you mean to add an empty space within quotes here to separate out the names? – aynber Oct 27 '21 at 15:53
  • Yes, that was the point. Good spot, thank you! – Alex Toma Oct 27 '21 at 15:55

0 Answers0