This problem gave me a headache for a couple hours, just to found out that there was a white space before <?php.

Next time you have this error too, check if there’s a white space before or after the PHP opening or closing tags.

Another suggest to remove ?> at the end of your codes.