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

My Code is coming up with all the possible errors if it exists whats wrong?

My Code is coming up with all the possible errors if it exists whats wrong?

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $name = trim($_POST['name']);
    $email = trim($_POST['email']);
    $message = trim($_POST['message']);
    $error_message = array (
        "all" => "You did not specify name, email and Message!",
        "info" => "There was a problem with the information you entered.",
        "submission" => "Your form submission has an error.",
        "email" => "you must specify a valid email address.",
        "declined" => "There was a problem sending the email:"

    );

    if ($name = "" or $email == "" or $message = "") {
        $error_message["all"];  
    }


    if (!isset($error_message)) {
        foreach ($_POST as $value) {
            if( stripos($value,'Content-Type:') != FALSE) {
                $error_message["info"]; 
            }
        }

        if (!isset($error_message) AND $_POST["address"] != "") {
            $error_message["submission"];
        }

        require_once("inc/phpmailer/class.phpmailer.php");
        $mail = new PHPMailer();
        if (!$mail ->ValidateAddress($email)); {

            $error_message["email"];
        }
    }
    if (!isset($error_message)) {
            $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@shirts4mike.com";
            $mail->AddAddress($address, "Shirts 4 Mike");
            $mail->Subject    = "Shirts 4 Mike Contact Form Submission |" . $name;
            $mail->MsgHTML($email_body);

                if($mail->Send()) {
                    header("Location: contact.php?status=thanks");
                    exit;                   
                } else {    
                    $error_message["declined"];
                }


} }
?>



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



        <div class="section page">

        <div id="wrapper">

                    <h1>Contact</h1>

                    <?php if (isset($_GET["status"]) and $_GET["status"] == "thanks") { ?>
                        <p>Thanks for the Email I will Get Back to you Shortly</p>
                    <?php   
                    } else { ?>



                    <?php if(!isset($error_message)) {
                        echo "<p>I would like to hear from you!</p>";
                    } else {
                        if (isset($error_message)) {
                            foreach ($error_message as $error) {                
                        echo '<p class="message">' . $error . '</p>';
                          }
                        }   
                    }

                    ?>
                    <form method="post" action="contact.php">
                        <table>
                          <tr>
                            <th><label for="name">Name</label></th><td><input type="text" name="name" id="name" value="<?php if (isset($name)) { echo htmlspecialchars($name); } ?>" ></td>
                          </tr>
                          <tr>
                            <th><label for="email">Email</label></th><td><input type="text" name="email" id="email" value="<?php if (isset($email)) { echo htmlspecialchars($email); } ?>" ></td>
                          </tr>
                          <tr>
                            <th><label for="message">Message</label></th><td><textarea name="message" id="message" ><?php if (isset($message)) { echo htmlspecialchars($message); } ?></textarea></td>
                          </tr>
                          <tr style="display:none;">
                            <th><label for="address">Address</label></th><td><input type="text" name="address" id="address" >
                            <p>Humans pleas do not fill in this field</p></td>
                          </tr>
                        </table>
                        <input type="submit" value="Send">
                    </form> <?php } ?>

        </div>

    </div>

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

I have not checked everything, but the first line has my attention. if ($name == '' or $email == '' or $message == ''). For some strange reason, it works by doing if ($name == '' || $email == '' || $message == ''). "||" also means or. If you are using or, you have to use it this way. if ( ($name == '') or ($email == '') or ($message == '') ). I'm very sleepy now so can't look through the other code, but that's a head start.