V
Vit
Vit said:Hi All,
I'm new to the perl language....
I'm trying to understand how this language work and I hav develop the
following code:
in the webpage:
<form action="\cgi-bin\my_email.cgi" method="post">
<input type="submit" name="Submit" value="Submit" style="width:
93px" />
in the cgi-bin directori the "my_email.cgi" file:
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, world!\n";
I'm using this file just to test.... and the result is that is not
working....
when I click to the "submit" button, I get the following message:
Server error!
The server encountered an internal error and was unable to complete
your request.
Error message:
Premature end of script headers: my_email.cgi
If you think this is a server error, please contact the webmaster.
Error 500
Tue Jun 9 14:11:00 2009
Apache/2.0.55 (Ubuntu) mod_ldap_userdir/1.1.11 PHP/4.4.2-1.1
mod_vhost_ldap/1.0.0
what can I do?? do you know what can I cahe to find out the issue???
thanks
Vit
-----------------------------
Did you solve your problem?
1. Make sure you upload your Perl script to the correct folder on yourweb
server, which I think would be something like /cgi-bin. Otherwise you may
get a 404 error, saying it can't find the file.
2. Once on the server, ensure that you change the file's properties to
executable, otherwise, I think you'll get error 403, something about
refusing to display web page.
3. I get the 500 Internal Server Error when I have an error in my code.. The
following script for example works fine:
#!/usr/bin/perl
$command= $];
$title = "Perl Version";
print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head><body>";
print "<h1>$title</h1>\n";
print "Perl version : ".$command;
print "<HR> \n";
system 'perl -v';
It displays the following -- yes I know it would be great if I had Perl 10
Perl Version
Perl version : 5.006001
-----------------------
This is perl, v5.6.1 built for i686-linux Copyright 1987-2001, Larry Wall
Perl may be copied only under the terms of either the Artistic Licenseor
the GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using `man perl' or `perldoc perl'. If you have access to the
Internet, point your browser athttp://www.perl.com/, the Perl Home Page.
If however, I forget a semi colon like:
#!/usr/bin/perl
$command= $] # <--- Forgot Semicolon
$title = "Perl Version";
print "Content-type: text/html\n\n";
print "<html><head><title>$title</title></head><body>";
print "<h1>$title</h1>\n";
print "Perl version : ".$command;
print "<HR> \n";
system 'perl -v';
I get the following:
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable
to complete your request.
Please contact the server administrator, or webmaster and inform them of the
time the error occurred, and anything you might have done that may have
caused the error.
More information about this error may be available in the server errorlog.
4. You can also access your perl scripts directly instead of submitting a
form, for example, type the following in your address bar, and also use
/cgi-bin/my_email.cgi instead of \cgi-bin\my_email.cgi like Sinan said..
http://yourserver/cgi-bin/my_email.cgi
5. On a side note, I use the .pl extension instead of .cgi, but I may be a
minority? I think I even read that it was better to not use any extension
claiming that people don't have to know that the script is Perl or whatever?
6. Your print code looks ok, so perhaps the trouble is in your (pound bang)
line? Like you, mine is:
#!/usr/bin/perl
But perhaps you require it like this: (user) instead of (usr)???
#!/user/bin/perl
7. Are you sure your system supports Perl? If so, check if there are some
default Perl scripts in the /cgi-bin folder and check if they work, and if
they do, start with them.
Finally, I'm quite new to this group and Perl so I expect to be corrected
here!
PS. I recently learned that instead of uploading my scripts to test them, I
could install Strawberry Perl on my Windows XP and test my scripts locally.
I upload them to the server only once the bugs are out.
Cheers,
Guy D.Thanks for the answer!!! really appreciate!!!I have solve the issue!!! was the permission on the .pl file (I set
utp the permission on the falder, but not on the file...now I'm trying to debug my file.... it works (no error in the
browser!!!), but it is not doing what I'd like to...#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
&send_email;
send_email();
sub send_email
{
$to = "vit\@domain.com";
open(MAIL, "|/usr/sbin/sendmail");
Always check for success/failure when opening a file handle.
Use lexical file-handles and the three-argument open.
(assuming your ancient perl supports them)
print MAIL "From: bob\@domain.com\n";
print MAIL "To: $to\n";
print MAIL "Subject: Web Enqiry\n\n";
Aren't you supposed to provide a message body terminated by a full-stop
on a line by itself?
close (MAIL);
I imagine sendmail was waiting for a message body?
print "Content-type: text/html\n\n";
Don't promise HTML if you are not willing to keep your promise.
print "Hello World2"
That isn't HTML.
it doesn't give me an error,
Ask perl to tell you of any errors! (see comment above).
Make sure errors are written somewhere you are looking.
See above `use CGI::Carp qw(fatalsToBrowser);`
Back in the days of Perl 4 I used
BEGIN {
open(STDERR ,'>&STDOUT')
|| die "Can't redir stderr to out: $!\n";
$| = 1; # Make it unbuffered
print "Content-type: text/html\n\n";
}
This is more in keeping with your rather quaint and archaic coding style
but I can't imagine your Perl installation could be so backward as to
lack a better way to redirect errors to the browser.
but I dont receive any mail....
Ask Perl to tell you why.
any suggestion???
See above.
I'd make more use of modules for CGI and for email.
thanks
thanks, I will try it!!!