Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Jeremy Byerly
Jeremy Byerly
10,659 Points

Working with Post Variables to transmit form data---Message of email is not being sent through to server

I'm working on 'Build a Simple PHP Application'. I'm on the lesson where we are setting up an HTML form to send an email from the 'Contact' section of the webpage.

In this stage of the lesson, we have written a file, 'contact-process.php', to simply output the form data to the browser so we can check that everything's being sent through. The name and email address are showing up, but the message isn't. I've run my html through the W3 validator and everything checked out.

Can someone help me take a look?

This is my html for the Contact page:

<?php
$pageTitle = "Contact Mike";
$section = "contact";
include('inc/header.php'); ?>

        <div class="section page">
          <div class="wrapper">
            <h1>Contact</h1>
            <p>I&rsquo;d love to hear from you! Complete the form to send me an email.</p>
            <form method="post" action="contact-process.php">
              <table>
                <tr>
                  <th>
                    <label for="name">Name</label>
                  </th>
                  <td>
                    <input type="text" name="name" id="name">
                  </td>
                </tr>
                <tr>
                  <th>
                    <label for="email">E-mail</label>
                  </th>
                  <td>
                    <input type="text" name="email" id="email">
                  </td>
                </tr>
                <tr>
                  <th>
                    <label for="message">Message</label>
                  </th>
                  <td>
                    <textarea name="messsage" id="message"></textarea>
                  </td>
                </tr>
              </table>
              <input type="submit" value="Send">
            </form>
          </div>
        </div>

<?php include('inc/footer.php'); ?>
` ` `


This is my 'contact-process.php' file:

` ` `php
<pre><?php
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$email_body = "";
$email_body = $email_body . "Name: " . $name . "\n";
$email_body = $email_body . "Email: " . $email . "\n";
$email_body = $email_body . "Message: " . $message . "\n";
echo $email_body;
?></pre>
` ` `


When I submit the form, the name and email address show up, but the message content is blank.

But when I run var_dump($_POST), the message shows up in the array.

Any idea what's going on here?

Thanks in advance!!

2 Answers

Aaron Graham
Aaron Graham
18,033 Points

your textarea name has three s's in message.

<textarea name="messsage" id="message"></textarea>

should be

<textarea name="message" id="message"></textarea>
Jeremy Byerly
Jeremy Byerly
10,659 Points

Oh man, how embarrassing!

Thanks a ton, man!

Aaron Graham
Aaron Graham
18,033 Points

Anytime! I can't even count the times I have spent hours troubleshooting code just to find something like this.