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
After many diff's, this was what was missing from the httpd.conf file on the server in question:
httpd.conf
AddHandler php5-script .php
Solved the issue.