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

instead of assigning $_POST values to $email_body one by one, cant we just assign them all at once? see the code below

$email_body = "Name: ".$name."<br>"."Email: ".$email."<br>"."Message: ". $message."<br>";

this code has the same HTML output as the script that Randy made in the final of the video. why did randy did so? should i be worried?

2 Answers

Fidel Torres
Fidel Torres
25,286 Points

HELLO giorgi shervashidze:

The output as you say is the same as Randys, but the only thing to worry about is that "$email_body" is going to be send in to an email and as per your code:

$email_body = "Name: ".$name."<br>"."Email: ".$email."<br>"."Message: ". $message."<br>";
/*
the <br> tag wont be interpreted in a email and the output will be:

the respective values of the variables but all in one line:

Name: $name Email: $email Message: $message 
*/

SOLUTION: Use the same code you have the only difference would be

<pre><?php

$email_body = "Name: ".$name."<br>"."Email: ".$email."<br>"."Message: ". $message."<br>";

/*change *< br >* for \n */

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

?></pre>

HOPE this anwser your question

yep thanks.