0

I've looked on this site for answers to my question, and have tried several of the suggestions I found, but nothing is getting rid of this error:

Warning: Cannot modify header information - headers already sent by (output started at /home/thegrowt/public_html/sfs/test.php:1) in /home/thegrowt/public_html/sfs/test.php on line 23

My PHP opens on line 1, there is nothing above it, and there aren't any stray spaces after each line....

<?php

if ($_POST) {
    if (empty($_POST['first']) || 
    empty($_POST['last']) || 
    empty($_POST['email']) ||
    empty($_POST['zip'])) {
        $errors = 1;
    } elseif (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
        $errors = 2;
    } else {
        $to = "test@test.com";
        $subject = "Subject";
        $message .= "First Name: ".$_POST['first']."\n";
        $message .= "Last Name: ".$_POST['last']."\n";
        $message .= "Email: ".$_POST['email']."\n";
        $message .= "Zip: ".$_POST['zip']."\n";
        $message .= "Country: ".$_POST['country']."\n";
        $message .= "Phone: ".$_POST['phone']."\n";
        $from = $_POST['email'];
        $headers = "From:" . $from;
        mail($to,$subject,$message,$headers);
        header('Location: thank-you.php');
        exit;
    }
}

if ($errors == 1) {
    $errors = "Please fill out all required fields!";
} elseif ($errors == 2) {
        $errors = "Please enter a valid email";
}

?>
<!doctype html>
<html>
<head>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">
<title>Title</title>
<link rel="stylesheet" href="css/main.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="js/modernizr.js"></script>
<script src="js/main.js"></script>
</head>
Amy
  • 9
  • 1
  • don't leave a byte order mark out of the equation. – Funk Forty Niner Aug 06 '15 at 17:46
  • I had to go into jEdit and remove BOM as an option. Saved out, reuploaded, and voila. Thanks so much. – Amy Aug 06 '15 at 17:55
  • You probably have some control characters before the PHP opening tag. Select all the code in test.php, copy and paste it into a simple text editor like Notepad on Windows, Kate on Linux/KDE, etc. save and try. – marekful Aug 06 '15 at 17:58

0 Answers0