Cannot modify header information - headers already sent by

I get the following error:

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /var/www/vhosts/vincennes.org/httpdocs/system/application/controllers/contact.php:11)

Filename: codeigniter/Common.php

Line Number: 356

on a contact.php page with the following code:
[php]form_validation->set_message(‘check_honeypot’, ‘Incorrect answer to the security question. Try again.’);
return FALSE;

}

function index() 
{
	$data['page_title'] = 'Contact';
	$data['page_description'] = 'Online contact form for The City of Vincennes, Indiana.';
	$data['keywords'] = 'contact, email, vincennes, city of vincennes, contacts, mail, get in touch, message';
	$data['breadcrumbs'] = '>Contact';
	$this->load->model('dept_model', 'dept');	
	$data['depts'] = $this->dept->getDepts();
	
	$rules = array(
	array(
	'field'=>'name',
	'label'=>'Name',
	'rules'=>'required|trim|max_length[100]'
	),
	array(
	'field'=>'address',
	'label'=>'Address',
	'rules'=>'trim|max_length[200]'
	),
	array(
	'field'=>'city',
	'label'=>'City',
	'rules'=>'trim|max_length[100]'
	),
	array(
	'field'=>'state',
	'label'=>'State',
	'rules'=>'trim|max_length[50]'
	),
	array(
	'field'=>'zip',
	'label'=>'Zip',
	'rules'=>'trim|max_length[20]|alpha_dash'
	),
	array(
	'field'=>'phone',
	'label'=>'Phone',
	'rules'=>'trim|max_length[20]'
	),
	array(
	'field'=>'email',
	'label'=>'Email',
	'rules'=>'trim|required|valid_email'
	),
	array(
	'field'=>'dept',
	'label'=>'Department',
	'rules'=>'trim|max_length[255]'
	),
	array(
	'field'=>'area',
	'label'=>'Area',
	'rules'=>'trim|max_length[255]'
	),
	array(
	'field'=>'method',
	'label'=>'Method',
	'rules'=>'trim|required|max_length[10]'
	),
	array(
	'field'=>'message',
	'label'=>'Message',
	'rules'=>'required|trim|min_length[10]'
	),
	array(
	'field'=>'honeypot',
	'label'=>'Security Question',
	'rules'=>'required|trim|numeric|callback_check_honeypot'
	)
	);
	$this->form_validation->set_rules($rules);
	
	if($this->form_validation->run() == FALSE)
	{
		$this->load->view('general/contact', $data);	
	} else {
		$this->load->library('email');
		$this->email->from($this->input->post('email'));
		$this->email->to(EMAIL_TO);
		$this->email->bcc('[email protected]');
		$this->email->subject('New contact form inquiry submitted from '.SITE_NAME);
		
		$msg = "There was a new contact form inquiry from ".base_url()."contact\r\n\r\n";
		$msg .= "Name: ".$this->input->post('name')."\r\n";
		$msg .= $this->input->post('address') ? 'Address: '.$this->input->post('address')."\r\n" : '';
		$msg .= $this->input->post('city') ? 'City: '.$this->input->post('city')."\r\n" : '';
		$msg .= $this->input->post('state') ? 'State: '.$this->input->post('state')."\r\n" : '';
		$msg .= $this->input->post('zip') ? 'Zip: '.$this->input->post('zip')."\r\n" : '';
		$msg .= $this->input->post('phone') ? 'Phone: '.$this->input->post('phone')."\r\n" : '';
		$msg .= 'Email: '.$this->input->post('email')."\r\n";
		$msg .= $this->input->post('dept') ? 'Direct message to: '.$this->input->post('dept')."\r\n" : '';
		$msg .= $this->input->post('area') ? 'Direct message to: '.$this->input->post('area')."\r\n" : '';
		$msg .= 'Respond to this message by: '.$this->input->post('method')."\r\n\r\n";
		$msg .= "Message:\r\n".$this->input->post('message')."\r\n\r\n";			
		$msg .= "This email was sent from ".base_url()."contact on ".date('n/j/Y').". The guest's IP address is ".$_SERVER['REMOTE_ADDR'].".\r\n";
		
		$this->email->message($msg);
		
		if($this->email->send())
		{
			$this->session->set_flashdata('info', 'Your message was successfully processed and sent to the necessary personel. We will respond to you soon.');
		} else {
			$this->session->set_flashdata('error', 'We are unable to send out emails at this time. Sorry for the inconvenience.');
		}	
		redirect('contact');				
	}		
}

}
/* End */[/php]

I know that there is spacing issue, I’m just not sure where. Can anyone help?

Couple of common causes for that error are:

a - you have a white space before the first tag on the page. You might have to open it up in a basic text editor to get rid of it. If you’re using dreamweaver, tell it not to save the DOM character when you do a manual save.

b - there can’t be any text sent to the screen when using header(). You can’t echo or print anything at all. There can’t be anything on the screen other than html, no error messages or other confirmations. This is also the most likely problem for you.

Also, what IS line 356 of contact.php? Show us the line you received the error on or perhaps a few lines above and below that line…

Sponsor our Newsletter | Privacy Policy | Terms of Service