Undefined Index in PHP using textarea
<p>I've seen dozens of posts about this issue and it basically comes down to a variable not being declared or given a value. However I'm 100% sure it's the same and declared.</p>

<p>I have a basic contact form in HTML and I want it to send me and e-mail when someone hits the submit button. I am debugging the code as well to see what the problem is. The only issue it can find is that there is an <code>Undefined Index</code> which belongs to my text area. </p>

<p>I know that the name of the textarea must be the same as the name on my <code>$_POST</code> in the PHP. Please take a look at the two sections of code and tell me if you can see why it wouldn't be fetching the information from my textarea. The name is <code>message-area</code>.</p>

<p>HTML</p>

<pre><code>&lt;form action="mail.php" method="post" name=contact-me-form &gt;
     &lt;label name="firstname secondname"&gt;Name: *&amp;nbsp;&lt;/label&gt;&lt;br&gt;
     &lt;input class="half-box" type="text" name="firstname" required &gt;
     &lt;input class="half-box" type="text" name="secondname" required &gt;&lt;br&gt;
     &lt;p class="first-name"&gt;First Name&lt;/p&gt;
     &lt;p class="second-name"&gt;Last Name&lt;/p&gt;&lt;br&gt;
     &lt;label name="email"&gt;Email Address: *&amp;nbsp;&lt;/label&gt;&lt;br&gt;
     &lt;input class="full-box" type="email" name="email" spellcheck="false" required&gt;&lt;br&gt;
     &lt;label name="subject"&gt;Subject:&amp;nbsp;&lt;/label&gt;&lt;br&gt;
     &lt;input class="full-box" type="text" name="subject"&gt;&lt;br&gt;
     &lt;label name="message"&gt;Message: *&amp;nbsp;&lt;/label&gt;&lt;br&gt;
     &lt;textarea name="message-area" form="contact-me-form" type="text"  placeholder="Please enter your message"&gt;&lt;/textarea&gt;
     &lt;button name="submit" type="submit" value="Submit"&gt;Submit&lt;/button&gt;
&lt;/form&gt;
</code></pre>

<p>PHP</p>

<pre><code>&lt;?PHP

  $to = "";
  $from = "";
  $first_name = '';
  $last_name = '';
   $subject = '';
  $message = null;

 error_reporting(-1);
 ini_set('display_errors', 'On');
 set_error_handler("var_dump");

if(isset($_POST['submit'])){
      $to = 'email@test.com';
      $from = $_POST['email'];
      $first_name = $_POST['firstname'];
      $last_name = $_POST['secondname'];
      $subject = $_POST['subject'];
      $message = $_POST["message-area"];
if($message == null){echo "no message detected";}

 $headers = "From: " . $from;
 $headers = "From:" . $to;
 mail($to,$subject,$message,$headers);
 }

 ?&gt;
</code></pre>

<p>As you can see the names are identical yet when I submit the data it comes up displaying the following. </p>

<blockquote>
  <p>int(8) string(29) "Undefined index: message-area" string(58) "/hermes/bosnaweb25a/b2294/ followed by a bit more information and my error gets displayed: ["message"]=> NULL } no message detected.</p>
</blockquote>

<p>I honestly have no idea why this isn't being picked up, can anyone with more experience highlight my mistake?</p>

<p><strong>EDIT 1</strong></p>

<p>This is not to do with dashes/hyphens as I've edited my code as you can see below. <strike>It's also important to note that if I change this to raw text it still doesn't work, still acts as if there is no data from the textarea.</strike></p>

<p><strong>HTML</strong></p>

<pre><code>                    &lt;form action="mail.php" method="post" id=contact-me-form &gt;
                    &lt;label name="firstname secondname"&gt;Name: *&amp;nbsp;&lt;/label&gt;&lt;br&gt;
                    &lt;input class="half-box" type="text" name="firstname" required &gt;
                    &lt;input class="half-box" type="text" name="secondname" required &gt;&lt;br&gt;
                    &lt;p class="first-name"&gt;First Name&lt;/p&gt;
                    &lt;p class="second-name"&gt;Last Name&lt;/p&gt;&lt;br&gt;
                    &lt;label name="email"&gt;Email Address: *&amp;nbsp;&lt;/label&gt;&lt;br&gt;
                    &lt;input class="full-box" type="email" name="email" spellcheck="false" required&gt;&lt;br&gt;
                    &lt;label name="subject"&gt;Subject:&amp;nbsp;&lt;/label&gt;&lt;br&gt;
                    &lt;input class="full-box" type="text" name="subject"&gt;&lt;br&gt;
                    &lt;label name="message"&gt;Message: *&amp;nbsp;&lt;/label&gt;&lt;br&gt;
                    &lt;textarea name="messagearea" type="text"  placeholder="Please enter your message"&gt;&lt;/textarea&gt;
                    &lt;button name="submit" type="submit" value="Submit"&gt;Submit&lt;/button&gt;
                &lt;/form&gt;
</code></pre>

<p>PHP</p>

<pre><code>&lt;?PHP

$to = "";
$from = "";
$first_name = '';
$last_name = '';
$subject = '';
$message = null;

error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");

 if(isset($_POST['submit'])){
   $to = 'harry.brockley@hotmail.co.uk';
   $from = $_POST['email'];
   $first_name = $_POST['firstname'];
   $last_name = $_POST['secondname'];
   $subject = $_POST['subject'];
   $message = $_POST["messagearea"];
if($message == null){echo "no message detected";}

$headers = "From: " . $from;
$headers = "From:" . $to;
mail($to,$subject,$message,$headers);
}

 ?&gt;
</code></pre>

<p><strong>EDIT 2</strong></p>

<p>Tested it with a hard coded value works so it has to be the variable name. It's just strange that it only happens on the textarea. </p>