in reply to form mail with post, getting "premature ending of script headers"

Ok, first a tip, try running your script from the command line, examples of both tests:
$ REQUEST_METHOD=GET QUERY_STRING='bob=jack&jane=janice' ./sendit.pl $ REQUEST_METHOD=POST CONTENT_LENGTH=20 ./sendit.pl <<EOF bob=jack&jane=janice EOF
Second, I have to admit that my fellow monks are correct, with their suggestion that you should use the CGI module, and should definately not allow unauthenticated users unchecked access to your mailserver, as it will quickly be overcome with spammers. But unfortunately, your bug wouldn't be fixed by either of their solutions, so I'll continue with the analysis. When I ran my tests, I got an error from perl which is causing your 500 error:
Undefined subroutine &main::LMAIL called at ./test.pl line 23.
Incidently, those error messages will also appear in your webservers error logs. If I look at line 23, I can see:
22: open (LMAIL, "|usr/sbin/sendmail -t"); 23: print LMAIL("To: $in{myEmail}\n"); 24: print LMAIL ("From: $in{Email}\n");
Notice the lack of a space between the filehandle LMAIL and your open parenthesis? Perl is interpreting that instance of LMAIL as a call to the function &LMAIL(), which doesn't exist. This is causing it to exit with the error printed above. Putting a space in there should fix your problem. Incidently, you'll also need one of those spaces on line 28 :)


   [ qi3ber ] I used to think that I knew it all, then I started to listen.

Replies are listed 'Best First'.
Re: form mail with post, getting "premature ending of script headers"
by jonadab (Parson) on Feb 25, 2003 at 15:55 UTC
    Incidently, those error messages will also appear in your webservers error logs.

    Err, yes, I was going to say something about that and forgot: any time you're working on a cgi script, you probably want to have a window tailing the server's error log. If you don't have access to the error logs on the server where this is ultimately going to run, then do your testing on another system first, where you do have access. I run Apache on my home PC and also on my workstation at work, not because they're servers, but so that I can test stuff before putting it on the server. If you're going to be doing cgi programming, it's well worth having Apache on your computer, for testing. Then you can watch the log as you make a change to your script, save it, switch back over to the browser, and hit reload.


    sub H{$_=shift;while($_){$c=0;while(s/^2//){$c++;}s/^4//;$ v.=(' ','|','_',"\n",'\\','/')[$c]}$v}sub A{$_=shift;while ($_){$d=hex chop;for(1..4){$pl.=($d%2)?4:2;$d>>=1}}$pl}$H= "16f6da116f6db14b4b0906c4f324";print H(A($H)) # -- jonadab