Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

PHP

Mike's T-shirt Store website

Hi I'm working on the Mike's T-shirt Store project and my Contact page has a server error, but I'm not sure what's causing it. Below is my code. If anyone knows what my error is please let me know.

Jason

<?php<?php

if ($_SERVER["REQUEST METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$message = $_POST["message"];
$em/treehouse.jasonblomquist.com/web/content/contact.phpail_body = "";
$email_body = $email_body . "Name: " . $name . "\n";
$email_body = $email_body . "Email: " . $email . "\n";
$email_body = $email_body . "Message: " . $message;

// TODO: Send Email

header("Location: contact-thanks.php?status=thanks");
exit;
}
?><?php

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


    <div class="section page">

        <div class="wrapper">

        <h1>Contact</h1>

        <?php if (isset($_GET ["status"]) and $GET["status"] =="thanks") { ?>
        <p>Thanks for the email! I&rsquo;ll be in touch with you shortly.</p>
        <?php } else { ?>

    <p>I&rsquo;d love to hear from you! Complete the form to send me an email.</p> 
            <form method="post" action="contact.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">Email</label>
                    </th>
                    <td>

                                    <input type="text"name="email" id="email">
                    </td>
                    </tr>

                    <th> 
                <label for="email">Message</label>
                    </th>
                    <td>

                    <textarea name="message" id="message"></textarea>
                    </td>
                    </tr>   
            </table>
                <input type="submit"value="send">
            </form>

                    <?php } ?>

        </div>

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

3 Answers

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

This line of code looks incorrect:

$em/treehouse.jasonblomquist.com/web/content/contact.phpail_body = "";

I think that should just say this:

$email_body = "";

Hi Randy, I still Get the server error when i go to the contact page, my code now is as follows:

<?php<?php

if ($_SERVER["REQUEST METHOD"] == "POST") { $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;

// TODO: Send Email

header("Location: contact-thanks.php?status=thanks"); exit; } ?><?php

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

<div class="section page">

    <div class="wrapper">

    <h1>Contact</h1>

    <?php if (isset($_GET ["status"]) and $GET["status"] =="thanks") { ?>
    <p>Thanks for the email! I&rsquo;ll be in touch with you shortly.</p>
    <?php } else { ?>

<p>I&rsquo;d love to hear from you! Complete the form to send me an email.</p> 
        <form method="post" action="contact.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">Email</label>
                </th>
                <td>

                                <input type="text"name="email" id="email">
                </td>
                </tr>

                <th> 
            <label for="email">Message</label>
                </th>
                <td>

                <textarea name="message" id="message"></textarea>
                </td>
                </tr>   
        </table>
            <input type="submit"value="send">
        </form>

                <?php } ?>

    </div>

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

any thoughts?

Jason

Randy Hoyt
STAFF
Randy Hoyt
Treehouse Guest Teacher

It starts with two sets of PHP opening tags:

<?php<?php

It should only have one of those.

<?php

Try that.