in reply to Re: Re: Premature end of script headers
in thread Premature end of script headers

I just ran it on my server, as you've posted it here, and it ran just fine, no "end of headers" message, but as you say, sent an email with no content.

That's pretty much what you'd expect running just that script by itself, because there's no form feeding it with information.

Here's a quick fix for your problem.

Start again.

Start with this code:

use CGI; use CGI::Carp qw(fatalsToBrowser); CGI::ReadParse();
now all the values from your form are in a hash called "%in".

So if you've got a field called "Title", the contents are now easily accessed because they're in $in{'Title'}.

Note that there's a case-sensitivity issue here too. If your form field is called "title" then you need $in{'title'} instead.

You don't need to grab things from the hash and put them into variables, just grab them directly from the hash, i.e. do this

print MAIL "$in{'Title'}\n";
in your mail-sending code, rather than doing that bizarre "GETVALUES" thing which is just double handling. Skip that stage altogether. Just go straight to sending the mail.

And the fatalsToBrowser thing will mean you get useful error messages.



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re: Re: Re: Re: Premature end of script headers
by Nickd_69 (Novice) on Aug 08, 2003 at 01:54 UTC
    I followed your instructions but the only thing I am having trouble with is the sendmail code. What are your suggestions? Thanks for all your help This is what I have so far
    #!/usr/bin/perl -w use CGI; use CGI::Carp qw(fatalsToBrowser); CGI::ReadParse(); print MAIL "$in{'Title'}\n"; print MAIL "$in{'Name'}\n"; print MAIL "$in{'Position'}\n"; print MAIL "$in{'School'}\n"; print MAIL "$in{'Address'}\n"; print MAIL "$in{'Suburb'}\n"; print MAIL "$in{'State'}\n"; print MAIL "$in{'PCode'}\n"; print MAIL "$in{'Email'}\n"; print MAIL "$in{'Phone}\n"; print MAIL "$in{'Fax'}\n"; print MAIL "$in{'PR02'}\n\n"; print MAIL "$in{'PR03'}\n"; print MAIL "$in{'PR04'}\n"; print MAIL "$in{'Att1'}\n"; print MAIL "$in{'Att2'}\n"; print MAIL "$in{'Att3'}\n"; print MAIL "$in{'Att4'}\n"; print MAIL "$in{'Att5'}\n"; print MAIL "$in{'Att6'}\n"; print MAIL "$in{'Att7}\n"; print MAIL "$in{'Att8'}\n"; print MAIL "$in{'Att9'}\n"; print MAIL "$in{'Comments'}\n"; $recipients = "dawson.nicholas.a\@edumail.vic.gov.au"; $mailprog = '/usr/sbin/sendmail'; open(MAIL,"|$mailprog -t"); print MAIL "To: $recipients \n"; print MAIL "From: $Email \n"; print MAIL "Subject: Travancore School Professional Development \n\n" +; print MAIL "Travancore School Professional Development\n\n"; print MAIL "Hi, I have just visited your website.\n\n"; print MAIL "Personal Details\n";
      Well if that's what you're using then you've just got the code in the wrong order.

      You can't print to MAIL before it's opened.

      Do the open() thing first, then all the prints.



      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss') =~y~b-v~a-z~s; print