-1

I'm working on a simple feedback submission form for my personal site. I am getting the following error

Warning: Cannot modify header information - headers already sent by (output started at /home/content/92/9339092/html/Pages/ArabicRootMachine/feedbackTEST.php:200) in /home/content/92/9339092/html/Pages/ArabicRootMachine/feedbackTEST.php on line 226*

I've tried adding ob_start() to buffer any output, but that didn't work. If I put the header() call at the beginning of the php script, the form works and sends the e-mail, but it doesn't redirect to the thank you page. Any of you superior mammals willing to breeze through to see if there is anything obvious that might throw this error?

Note: Line 200 is the beginning of the script (the php open tag), line 226 is the header call.

<?php
include('./includes/title.inc.php'); 
require_once('./includes/recaptchalib.php'); 
$public_key = '****************************************'; 
$private_key = '****************************************'; 
$errors = array(); 
$missing = array(); 
// check if the form has been submitted 
if (isset($_POST['send'])) { 
    // email processing script
    $to = 'blahblah@gmail.com';
    $subject = 'Feedback on Root Machine'; 
    // list expected fields 
    $expected = array('name', 'email', 'comments'); 
    // set required fields 
    $required = array('name', 'email', 'comments'); 
    // create additional headers 
    $headers = "From: My Next Bit<feedback@mynextbit.com>\r\n"; 
    $headers .= 'Content-Type: text/plain; charset=utf-8';
    $response = recaptcha_check_answer($private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field']);
    if (!$response->is_valid) { 
        $errors['recaptcha'] = true; 
    } 
    require('./includes/processmail.inc.php');
    if ($mailSent) {
        header('Location: http://www.mynextbit.com/Pages/ArabicRootMachine/thank_you.php'); 
    exit(); 
    }
}
?>

Please let me know if you need to see either of the **.inc.php files. I very much appreciate any help.

Bonedancer
  • 167
  • 1
  • 2
  • 13

3 Answers3

0

You cannot do this

header('Location: ... 

if you're doing this

include('./includes/title.inc.php');

Once you've sent headers, the PHP function header can't be used.

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called.

Documentation

Kermit
  • 33,827
  • 13
  • 85
  • 121
  • Thank you Fresh Prince of Stack Overflow. I'm buildling this in dreamweaver using templates. I did in fact have some HTML/CSS happneing before my php script. I just cut the entire script and put it before the – Bonedancer Aug 30 '13 at 01:28
0

Your include or require files may be sending actual output before header is used.

"Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include, or require, functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file." PHP.NET at http://php.net/manual/en/function.header.php

KC135Q
  • 44
  • 4
0
header("Location: link") 

should be before any html contents or function showing content (echo, print..)

Move the content that send the email to the top of you page it's obligatory.

mbouzahir
  • 1,424
  • 13
  • 16