SPUG: Mail::Mailer ...Help!

Doug Beaver dougb at scalar.org
Mon May 8 23:45:43 CDT 2000


On Tue, May 09, 2000 at 12:15:55AM -0400, Shamon22 at aol.com wrote:
> Thanks for the good suggestions! But alas I still am not able to get the darn 
> script to work right.
> 
> Am I just way off in the way I wrote this script? I keep getting the error 
> message:
> 
> [Mon May  8 15:15:09 2000] [error] Premature end of script headers: 
> /home/httpd/cgi
> -bin/contact2.cgi
> 
> What is PERL trying to tell me? What does it mean "Premature end of script 
> headers"?

That's an error from Apache, it's telling you that the CGI isn't
printing proper headers.  Printing the proper headers in a CGI usually
consists of printing the Content-Type header, the server should take
care of the rest.  You *do* need to print some sort of Content-Type
header in order for the CGI to run okay.

Here's a small CGI that just prints the Content-Type headers and exits:

% cat d
#!/usr/bin/perl

use CGI;
print CGI->header();
exit;

% telnet scalar.org 80

GET /cgi-bin/d HTTP/1.0

HTTP/1.1 200 OK
Date: Tue, 09 May 2000 04:28:22 GMT
Server: Apache/1.3.9 (Unix)
Connection: close
Content-Type: text/html

It ran okay and even though it didn't print anything after the HTTP
headers like a normal CGI would, it didn't throw a server error either.

If you comment out the "print CGI->header();" line in d, then you get:

% telnet scalar.org 80

GET /cgi-bin/d HTTP/1.0  

HTTP/1.1 500 Internal Server Error
Date: Tue, 09 May 2000 04:31:35 GMT
Server: Apache/1.3.9 (Unix)
Connection: close
Content-Type: text/html

[ I'll skip the html that gets printed out after the HTTP headers. ]

So, all you have to do is use the CGI module and print the Content-Type
headers in your CGI and it shouldn't throw server errors anymore.  You
need to print the headers before you print anything else out from the
script (otherwise you'll get more warnings about premature end of script
headers).

Doug

> Here is the most current rendition of my script:
> 
> ***************************************************************
> #!/usr/bin/perl -w
> # cgi-bin/contact.cgi:Information sending program.
> # TESTING --Send information (v2)
> 
> use Mail::Mailer;
> 
> $email  ='email';
> $mailto ='mailto';
> $subject ='subject';
> $body = 'body';
> $mailer = Mail::Mailer->new("sendmail");
> $mailer->open({ From    => $email,
>                 To      => $mailto,
>                 Subject => $subject,
>                 })
>         or die "Can't open: $!\n";
> print $mailer $body;
> $mailer->close();
> ******************************************************************
> 
> As a side note, if any of you all want to help answer my questions about 
> virtual domain hosting please let me know! I can't get my Linux box to host 
> virtual domains.
> 
> Help!
> 
> -Garrett
> 
>  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>      POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
>  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
>  For Subscriptions, Email to majordomo at pm.org:  ACTION  spug-list  EMAIL
>   Replace ACTION by subscribe or unsubscribe, EMAIL by your Email address
> 
> 

-- 
Smithers: I'm afraid we have a bad image, Sir.  Market research shows
          people see you as somewhat of an ogre.
   Burns: I ought to club them and eat their bones!

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 For Subscriptions, Email to majordomo at pm.org:  ACTION  spug-list  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email address





More information about the spug-list mailing list