Those blank lines between your ?>
and <?php
tags are being sent to the client.
When the first one of those is sent, it causes your headers to be sent first.
Once that happens, you can't modify the headers any more.
Remove those unnecessary tags, have it all in one big <?php
block.