I get a \"Premature end of script headers: contactform.cgi\" error message when running the below script. What frustrates me is that I ran this as a .php on another server
It is to do with file permissions and it happens on systems that have the suphp(usually cpanel/whost servers) installed.
Removing the write permission from anyone else but the owner(644|600) for the php files will fix the issue. That is how i got it fixed.
I hope this helps.