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

Nickd_69,
It looks like the sole purpose of the CGI is to send the form information to an email address and then redirect to a new URL. This could probably be done with just JavaScript.

I came up with the following code, but have no idea if it will work correctly as I am on a machine without a web server. It is more concise and it should be a lot easier to debug than your original script. I did verify the syntax using perl -c.

#!/usr/bin/perl -wT use strict; use CGI; use Mail::Mailer; my $query = CGI->new(); my %DATA = $query->Vars; my $body = "Hi, I have just visited your website.\n\n"; $body .= "Personal Details\n"; $body .= join "\n" , @DATA{qw(Title Name Position School Address Subur +b State PCode)}, ''; $body .= "Contact Details:\n"; $body .= "Tel: $DATA{Tel}\n"; $body .= "Tel: $DATA{Fax}\n"; $body .= "Tel: $DATA{Email}\n\n"; $body .= "I would like to register for the following presentations.\n" +; $body .= join "\n" , @DATA{qw(PR01 PR02 PR03 PR04 PR05 PR06 PR07 PR08) +}, ''; $body .= "List of Attendees.\n"; $body .= join "\n" , @DATA{qw(Att1 Att2 Att3 Att4 Att5 Att6 Att7 Att8 +Att9)}, ''; $body .= "Comments:\n"; $body .= "$DATA{Comments}\n\n"; my $mailer = new Mail::Mailer ( "smtp" ); $mailer->open( { To => 'info@travancoresch.vic.edu.au', From => $DATA{Email}, Subject => 'Travancore School Professional Development' } ); print $mailer $body; $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');

You really should get in the practice of validating form information. I have turned on Taint with the -T shebang line option as a future precaution against accepting user data without sanitizing it first if the script's functionality expands.

Cheers - L~R

Update: With some help from the CB, a few minor nits have been corrected

Replies are listed 'Best First'.
Re: Re: Re: Re: Premature end of script headers
by Anonymous Monk on Aug 04, 2003 at 23:37 UTC
    I tried to make my own code up using the second response and taking the sendmail out of the first lot of code you gave me but I am still having no luck. Could you just have a look at my revised code and give me some thoughts and feedback. I tried the original script but I couldn't even get that working. Thanks heaps for your time. I thought no one would help but you have been more than helpful.
    #!/usr/bin/perl -wT 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{'Telephone'}\n"; print MAIL "$in{'Fax'}\n"; print MAIL "$in{'PR01'}\n"; print MAIL "$in{'PR02'}\n"; print MAIL "$in{'PR03'}\n"; print MAIL "$in{'PR04'}\n"; print MAIL "$in{'PR05'}\n"; print MAIL "$in{'PR06'}\n"; print MAIL "$in{'PR07'}\n"; print MAIL "$in{'PR08'}\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"; my $mailer = new Mail::Mailer ( "smtp" ); $mailer->open( { To => 'dawson.nicholas.a@edumail.vic.gov.au', From => $in{'Email'}, Subject => 'Travancore School Professional Development' } ); print $mailer; $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');
      Nickd_69,
      Ok - you have forgetten to use Mail::Mailer which might just be a typo on your part. I would suggest reading the docs - it can use Sendmail if you want by replacing 'smtp' with 'sendmail'.

      Additionally - you are printing to the MAIL filehandle, but haven't opened it anywhere. You don't want to do that. Move the my $mailer = stuff before any of the print statements and then change all the MAIL lines to $mailer.

      You also didn't create the CGI object used to redirect the page later.

      You really want to look into hash slices. It could make your life a lot easier. The problem is that unless you have done form validation using JavaScript - you might be attempting to print an uninitalized variable. See my update to your code below:

      #!/usr/bin/perl -wT use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer; CGI::ReadParse(); my $query = CGI->new(); my $mailer = new Mail::Mailer ( "smtp" ); $mailer->open( { To => 'dawson.nicholas.a@edumail.vic.gov.au', From => $in{'Email'}, Subject => 'Travancore School Professional Development' } ); print $mailer "$in{'Title'}\n"; print $mailer "$in{'Name'}\n"; print $mailer "$in{'Position'}\n"; $mailer->close; print $query->redirect('http://www.travancoresch.vic.edu.au/developmen +t/reply02.html');
      That should move you along I think, still don't have a web server to test it on though. What were the errors you got with my code anyway?

      Cheers - L~R