This error message gets triggered when anything is sent before you send HTTP headers. Common reasons for outputting something before the HTTP headers are:
Accidental whitespace, often at the beginning or end of files, like this:
// Note the space before "<?php"
To avoid this, simply leave out the closing ?> - it's not required anyways.
Hope it helpss!!