Feedback form using cgi script
Feedback form using cgi script
am 14.08.2007 18:10:46 von Death
Hi there!
I have some problem in sending mail out from the server using the
script below
and it come error 500 internal error, pls contact server
administrator
Is there any problem with the code or ...?
Pls advise as i'm new in the cgi script :
#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
open (MESSAGE,"| /usr/sbin/sendmail -t");
print MESSAGE "To: test\test.com\n";
print MESSAGE "From: " . $FORM{name} . ", reader\n";
print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")
\n";
print MESSAGE "Subject: Feedback from $FORM{name} \n\n";
print MESSAGE "$FORM{name} wrote:\n\n";
print MESSAGE "Comment: $FORM{comment}\n\n";
print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";
close (MESSAGE);
&thank_you; #method call
}
sub thank_you {
print "Content-type: text/html\n\n";
print <
Thank You
Thank You
Your feedback has been received. Thanks for sending it.
EndStart
print "You wrote:
\n";
print "$FORM{comment}
\n\n";
print <
EndHTML
exit(0);
}
Re: Feedback form using cgi script
am 14.08.2007 18:27:51 von patrick
On Aug 14, 9:10 am, LaMoRt wrote:
> Hi there!
>
> I have some problem in sending mail out from the server using the
> script below
> and it come error 500 internal error, pls contact server
> administrator
>
> Is there any problem with the code or ...?
>
> Pls advise as i'm new in the cgi script :
>
> #!/usr/bin/perl
> use CGI::Carp qw(fatalsToBrowser);
>
> if ($ENV{'REQUEST_METHOD'} eq 'POST') {
>
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> @pairs = split(/&/, $buffer);
>
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> }
>
> open (MESSAGE,"| /usr/sbin/sendmail -t");
>
> print MESSAGE "To: test\test.com\n";
> print MESSAGE "From: " . $FORM{name} . ", reader\n";
> print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")
> \n";
>
> print MESSAGE "Subject: Feedback from $FORM{name} \n\n";
>
> print MESSAGE "$FORM{name} wrote:\n\n";
> print MESSAGE "Comment: $FORM{comment}\n\n";
> print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";
>
> close (MESSAGE);
>
> &thank_you; #method call
>
> }
>
> sub thank_you {
>
> print "Content-type: text/html\n\n";
>
> print <
>
>
>
> Thank You
>
>
>
>
> Thank You
>
> Your feedback has been received. Thanks for sending it.
>
>
>
> EndStart
>
> print "You wrote:
\n";
> print "$FORM{comment}
\n\n";
>
> print <
>
>
>
>
> EndHTML
>
> exit(0);
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -
You're missing the @ - print MESSAGE "To: test\@test.com\n";
Re: Feedback form using cgi script
am 14.08.2007 18:32:18 von Paul Lalli
On Aug 14, 12:10 pm, LaMoRt wrote:
> I have some problem in sending mail out from the server using the
> script below
> and it come error 500 internal error, pls contact server
> administrator
perldoc -q 500
> Is there any problem with the code or ...?
There are many problems with this code. Which of them might be
causing your error is impossible to determine with what you've given
us.
> Pls advise as i'm new in the cgi script :
>
> #!/usr/bin/perl
You're not using strict, or warnings.
use strict;
use warnings;
> use CGI::Carp qw(fatalsToBrowser);
The fact that you're using CGI::Carp, and yet still getting an HTTP
500 suggests that this program isn't being executed at all. Check the
permissions of the script, and make sure the webserver user has
permission to execute it.
You're not using the CGI module, and instead trying to parse the HTTP
content yourself.
use CGI qw/:standard/;
> if ($ENV{'REQUEST_METHOD'} eq 'POST') {
>
> read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
> @pairs = split(/&/, $buffer);
>
> foreach $pair (@pairs) {
> ($name, $value) = split(/=/, $pair);
> $value =~ tr/+/ /;
> $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
> $FORM{$name} = $value;
> }
Eliminate all of the above, and replace with:
my %FORM;
$FORM{$_} = param($_) for param();
> open (MESSAGE,"| /usr/sbin/sendmail -t");
You're not checking the return value of this pipe. You have no way of
knowing if the /usr/sbin/sendmail program even exists, let alone if it
was successfully started.
open my $MESSAGE, '| /usr/sbin/sendmail -t'
or die "Could nost start sendmail: $!";
>
> print MESSAGE "To: test\test.com\n";
> print MESSAGE "From: " . $FORM{name} . ", reader\n";
> print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")
> \n";
>
> print MESSAGE "Subject: Feedback from $FORM{name} \n\n";
>
> print MESSAGE "$FORM{name} wrote:\n\n";
> print MESSAGE "Comment: $FORM{comment}\n\n";
> print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";
Replace all of those MESSAGE filehandles with $MESSAGE.
> close (MESSAGE);
You're not checking the return value of closing this pipe, to know if
sendmail had any problems:
close $MESSAGE or die "Error when closing sendmail: $! ($?)\n";
>
> &thank_you; #method call
That's not a method call, it's a subroutine call, and you shouldn't be
calling it with the & on the front.
thank_you(); #subroutine call
>
> }
>
> sub thank_you {
>
> print "Content-type: text/html\n\n";
print header();
>
> print <
>
>
>
> Thank You
>
>
>
print start_html(-title => "Thank You");
>
> Thank You
>
> Your feedback has been received. Thanks for sending it.
>
>
print h1("Thank you"),
p("Your feedback has been received. Thanks for sending it.),
hr();
>
> EndStart
>
> print "You wrote:
\n";
> print "$FORM{comment}
\n\n";
print p("You wrote:"), blockquote(em($FORM{comment}));
>
> print <
>
>
>
>
> EndHTML
print end_html();
>
> exit(0);
no need for that at all.
Paul Lalli
Re: Feedback form using cgi script
am 14.08.2007 18:44:02 von paduille.4061.mumia.w+nospam
On 08/14/2007 11:10 AM, LaMoRt wrote:
> Hi there!
>
> I have some problem in sending mail out from the server using the
> script below
> and it come error 500 internal error, pls contact server
> administrator
> [...]
Look into the server logs to see what error was generated by your script.
Re: Feedback form using cgi script
am 14.08.2007 19:13:01 von Death
Thanks all for the help..
I will try out the solution u all give and tested it.
Re: Feedback form using cgi script
am 14.08.2007 22:18:26 von Gunnar Hjalmarsson
LaMoRt wrote:
> I will try out the solution u all give and tested it.
Whatever you do, don't put the script on a publicly available server. It
can easily be abused to send spam to multiple recipients, even if you
adopt the changes Paul and other suggested.
You may want to try the CPAN module CGI::ContactForm for a safer solution.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl