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!

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


contact page : php mailer


this is my second time to apply the phpmailer way to my project. but I don't seem to understand what has gone wrong this time. the form is working, I'm receiving the messages in my email but the page is after sent is just white, I also don't see the url change to contact.php?status.

Can someone state here scenarios that could have caused this or I should paste the code here?

thanks, don


4 Answers

Andrew Shook
Andrew Shook
31,709 Points

That's great Don, I hope I was a little helpful.

yes you were, that's why I gave you a plus 1. then I noticed you have 13k points lol.

Andrew Shook
Andrew Shook
31,709 Points

Hey, I just submitted the contact form you posted above, and got the "White screen of death". This is usually caused because of a syntax error like forgetting to end a statement with a semi-colon or having too many ")" or "}". If you have access to it you should turn on php error messaging and check your server's php error log which can usually be found in "/var/log/" (this can be different depending on you server's setup). If you feel comfortable post the code for that page I can take a look at it.

Hi Andrew,

Thanks for the reply.

I look again at my code but I really don't see where I got the error.


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

        if($name == "" OR $number == "" OR $email == "" OR $message  =="") {
            echo "you must specify a value for name, contact number, email address, and message";

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

        if ($_POST["dummy"] != ""){
            echo "Your from submission has an error.";


        $mail             = new PHPMailer();
            echo "You must enter a valid email address";

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

        $mail->SetFrom($email, $name);

        $address = "donbenci13@gmail.com";

        $mail->AddAddress($address, "Supercon");

        $mail->Subject    = "Supercon Pest Control Webform | " . $name;


        if(!$mail->Send()) {
          echo "Mailer Error: " . $mail->ErrorInfo;

        header("Location: contact.php?status=thanks");

<?php if(isset($_GET["status"]) AND $_GET["status"] == "thanks"){?>
    <p>Thanks for the email! We will be in touch shortly.</p>
<?php } else{ ?> 
Andrew Shook
Andrew Shook
31,709 Points

You have an open else statement at the bottom of your php script. Not sure is the forum cut it off or if it is actually open. Check you script, if there isn't a closing curly brace at the end of the file then you need to add one. PHP will white screen if you open a code block and don't close it.

sorry i have that at the bottom <?php } ?>

I checked the php error logs and this is the error

PHP Warning: Cannot modify header information - headers already sent by (output started at /..) in /.. on line 57

it's pointing out the header()

but I don't get it, this is working for my the last time I used this. I only added the $number variable to the code.