A file download cannot occur on a page with other processing, it will not work.
Downloading a file is done through manipulating the pages header.
The email redirect is also done through manipulating the pages header.
The header manipulation done by the download function will prevent any other header action from occurring.
To work around this, you should perform the file download on the thank page that the email behavior redirects to.
as for the errors, thee are cause by a blank line between php code blocks on line 7 or 8.
Seethe following thread for more details on the headers already sent error: