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 Build a Simple PHP Application Adding a Contact Form Working with Concatenation and Whitespace

Message not popping up!

So my message is not popping up and I am having an extra line break! Someone please help!

http://gyazo.com/7b8385652d19f03ef04ba7298e461d85

Here is my process file code.

<?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;

echo $email_body;

?>

2 Answers

I understand this is a matter of personal preference, but for me I do not like building out the body the way you are doing, I prefer this method because I think it's much cleaner and easier to read:

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$body = "Name: $name\n";
$body .= "Email: $email\n";
$body .= "Message: $message";

echo $body;
?>

With that said, what does the markup look like for your input fields?

I just continued with the exercises. Seems to work fine now thanks though man!

OK, well in case this can be helpful to anyone else you can do a pretty simple echo test on $body like so:

<?php
$success = FALSE;

if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    $email = $_POST['email'];
    $message = $_POST['message'];

    $body = "Name: $name\n";
    $body .= "Email: $email\n";
    $body .= "Message: $message";

    $success = TRUE;
}
?>

and within the body of your page, for testing, you could use:

    <?php
    if($success == TRUE) {
        echo $body;
    }
    ?>
    <form action="" method="post">
        <input name="name">
        <input name="email">
        <textarea name="message"></textarea>
        <input name="submit" type="submit">
    </form>

This is a very, very basic test, we aren't doing any error handling, basically on submit we are just assigning the post values to variables, building the body, and then using a boolean as our success variable. If success is true down in the body we echo out the results of $body, so if the $body echos to the page with all the values you put in, you know that the input values are properly being assigned to variables.