Rather than filtering out embedded newlines in those form fields, it would be preferable to log an error, return an error message and attempt to send no email.
As someone has compromised your site, you must do the following:
- Shut the site down immediately, change your passwords to your hosting
- Notify your hosting provider who will doubtless need to reinstall the box having moved all hosted sites off it.
- On a test box, restore all your code and data from the last known good backup - go through it with a fine-tooth comb to check for unauthorised modifications. Ideally restore all your code from a known good version (the one you keep in your SCM system).
If your site uses passwords for end-users, they all need to be changed. If your site has administrative logins then they need to be checked carefully to make sure no new ones have appeared (ideally just disable them all and re-enable them on an as-needed basis).
Your site's been compromised - nothing less than a reinstall will clean it.
Bear in mind that your desktop (or one of your users' desktops) may have been compromised - you should check this too.
Mark