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

don bencilao
4,153 Pointscontact page : php mailer
hi,
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

don bencilao
4,153 Pointsdude I fixed it, I changed the encoding to without BOM
I read it here: http://www.arclab.com/en/webformbuilder/php-warning-cannot-modify-header-information-headers-already-sent.html

Andrew Shook
31,709 PointsHey, 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.

don bencilao
4,153 PointsHi Andrew,
Thanks for the reply.
I look again at my code but I really don't see where I got the error.
<?php
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";
exit;
}
foreach( $_POST as $value ){
if( stripos($value,'Content-Type:') !== FALSE ){
echo "The was a problem with the information you entered.";
exit;
}
}
if ($_POST["dummy"] != ""){
echo "Your from submission has an error.";
exit;
}
require_once('inc/phpmailer/class.phpmailer.php');
$mail = new PHPMailer();
if(!$mail->ValidateAddress($email)){
echo "You must enter a valid email address";
exit;
}
$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;
$mail->MsgHTML($email_body);
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}
header("Location: contact.php?status=thanks");
exit;
}
?>
<?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
31,709 PointsYou 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.

don bencilao
4,153 Pointssorry i have that at the bottom <?php } ?>

don bencilao
4,153 PointsI 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.
Andrew Shook
31,709 PointsAndrew Shook
31,709 PointsThat's great Don, I hope I was a little helpful.
don bencilao
4,153 Pointsdon bencilao
4,153 Pointsyes you were, that's why I gave you a plus 1. then I noticed you have 13k points lol.