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

PHP Parse error

I'm having a few issues with my PHP form. Whenever I view this in a browser I get the following message: Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\festivival\contact.php on line 122 But I can't see anything wrong with the code! Apologies is this isn't the correct place for this discussion - but its really bugging me!

Here's my code:

<?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $name = trim($_POST["name"]); $email = trim($_POST["email"]); $message = trim($_POST["message"]);

if ($name == "" OR $email == "" OR $message =="") {
        echo "Please enter information for name, email address and message";
        exit; 
    }

foreach ( $_POST as $value){
    if( stripos($value, 'Content-Type') !== FALSE) {
        echo "There was a problem with the information you entered.";
        exit;
    }
}

if ($_POST["address"] != "") {
    echo "Your form submission has an error";
    exit;
}

require_once("inc/phpmailer/class.phpmailer.php");
$mail = new PHPMailer();
if (!$mail->ValidateAddress($email)) {
    echo "Please enter a valid email address.";
    exit;
}


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



$mail -> SetFrom($email, $name);
$address = "orders@revivalsurvival.co.uk";
$mail->AddAddress($address, "Bola Ajayi");
$mail->Subject    = "Revival Survival contact form submission -" . $name;
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; 
$mail->MsgHTML($email_body);

if(!$mail->Send()) {
  echo "Hmm, there seems to be a problem sending your email: " . $mail->ErrorInfo;
  exit;
} 
header("Location: contact.php?status=thanks");
exit; ?>

<?php $pageTitle = "Contact Us"; $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 your email! We'll get back to you as soon as possible.</p>


            <?php } else { ?>

                <p>Got a question or query? Get in touch I would love to hear from you!<br>
                Complete the form below to send me an email.</p>

                <form method="post" action="contact.php">
                    <table>
                    <tr>
                        <th>
                            <label for="fullname">Name:</label>
                        </th>
                        <td>
                            <input type="text" name="name" id="name" placeholder="John Smith">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <label for="email">Email address:</label>
                        </th>
                        <td>
                            <input type="text" name="email" id="email" placeholder="example@example.com">
                        </td>
                    </tr>
                    <tr>
                        <th>
                            <label for="message">Message:</label>
                        </th>
                        <td>
                            <textarea name="message" id="message" placeholder="Enter your messsage here"></textarea>
                        </td>
                    </tr>
                    <tr style="display: none;">
                        <th>
                            <label for="address">Address:</label>
                        </th>
                        <td>
                            <input type="text" id="address"></textarea>
                            <p>Humans - please leave this blank!Its just a security precaution!</p>
                        </td>
                    </tr>

                    </table>
                    <input type="submit" value="Send">


                </form>

                <?php } ?>

        </div>

</div>

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

2 Answers

Daniel Gibson
Daniel Gibson
15,452 Points

I think you are missing a closing } it looks like you haven't closed the if ($_SERVER["REQUEST_METHOD"] == "POST") statement

Thanks so much! It was a missing closing curly bracket - just after the last 'exit;' command.