phphtmlforms

Basic PHP contact form receiving email but no message


I'm using a guide found online for my first PHP contact form. Everything works great and the email is received except the message field is blank, all other parts are fine. I've taken a good look and there are hundreds of similar issues posted but I can't find any answers that work for me, sorry if the answer's out there already, all help greatly appreciated.

HTML:

    <div class="contactform">
    <h1>YOUR NAME</h1>
        <form class="commentform" action="message.php" method="post">
            <input type="text" name="name" class="nametext">
            <br />
    <h1>YOUR EMAIL</h1>
            <input type="email" name="email" class="emailtext">
            <br />  
    <h1>YOUR MESSAGE</h1>
            <textarea placeholder="Don't hold back..." name="message" form="commentform" class="textbox"></textarea>
            <br />
            <input type="submit" name="submit" value="LET'S TALK" class="submit">
        </form>
</div>  

PHP:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$formcontent="From: $name \n Message: $message";
$recipient = "someone@mailup.net";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";

?>


Solution

  • Remove the form="commentform" attribute from the messagetextarea...

    <textarea placeholder="Don't hold back..." name="message" class="textbox"></textarea>
    

    It's not necessary, because the textarea is a child of the form tag.

    In this case, it is actually preventing you from receiving the value, because your form tag does not have id="commentform", so you telling the browser that your textarea belongs to a non-existent form.