Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy PERL mail form - Internal Server Error

    This script was provided to me by my professor to use with a form we were to create using html/javascript to send e-mail. My form is working fine, but when the form is submitted, there is an internal server error. It seems there may be some syntax errors in the perl script, but I cannot figure it out. Any suggestions?


    #!/usr/local/bin/perl

    # ------------------------------------------------------------
    # Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
    #
    # Last updated: March 14, 1994
    #
    # Form-mail provides a mechanism by which users of a World-
    # Wide Web browser may submit comments to the webmasters
    # (or anyone else) at a site. It should be compatible with
    # any CGI-compatible HTTP server.
    #
    # Please read the README file that came with this distribution
    # for further details.
    # ------------------------------------------------------------

    # ------------------------------------------------------------
    # This package is Copyright 1994 by The Tech.

    # Form-mail is free software; you can redistribute it and/or modify it
    # under the terms of the GNU General Public License as published by the
    # Free Software Foundation; either version 2, or (at your option) any
    # later version.

    # Form-mail is distributed in the hope that it will be useful, but
    # WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    # General Public License for more details.

    # You should have received a copy of the GNU General Public License
    # along with Form-mail; see the file COPYING. If not, write to the Free
    # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
    # ------------------------------------------------------------

    # Define fairly-constants

    # This should match the mail program on your system.
    $mailprog = '/usr/lib/sendmail';

    # This should be set to the username or alias that runs your
    # WWW server.

    $recipient = getpwuid($<);
    $recipient .= "\@";
    $recipient .= `hostname`;

    if ($recipient eq "\@csprofessor.com") {
    $recipient = $ENV{'SERVER_ADMIN'};
    }

    # Print out a content-type for HTTP/1.0 compatibility
    print "Content-type: text/html\n\n";

    # Get the input
    read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

    # Split the name-value pairs
    @pairs = split(/&/, $buffer);

    foreach $pair (@pairs)
    {
    ($name, $value) = split(/=/, $pair);

    # Un-Webify plus signs and %-encoding
    $value =~ tr/+/ /;
    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;

    # Stop people from using subshells to execute commands
    # Not a big deal when using sendmail, but very important
    # when using UCB mail (aka mailx).
    # $value =~ s/~!/ ~!/g;

    # Uncomment for debugging purposes
    # print "Setting $name to $value<P>";

    $FORM{$name} = $value;
    }

    # If the comments are blank, then give a "blank form" response

    unless ($FORM{'realname'}) { &blank_response("name"); }
    unless ($FORM{'email'} ) { &blank_response("email"); }
    unless ($FORM{'message'} ) { &blank_response("message"); }
    unless ($FORM{'rating'} ) { &blank_response("rating"); }

    # Print a title and initial heading
    print "<html>\n";
    print "<Head><Title>Thank you</Title></Head>";
    print "<Body><H1>Thank you</H1>";
    print "<p>Thank you for sending your comments!<br>";
    print "</body></html>";

    # Now send mail to $recipient

    open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
    print MAIL "To: sgifford\@csprofessor.com\n";
    #print MAIL "To: $recipient\n";
    print MAIL "From: $FORM{'email'} ($FORM{'realname'})\n";
    print MAIL "Reply-to: $FORM{'email'} ($FORM{'realname'})\n";
    print MAIL "Subject: Web Site Comments\n\n";
    print MAIL "------------------------------------------------------------\n";
    print MAIL "$FORM{'email'} ($FORM{'realname'}) Stopped by\n";
    print MAIL "Phone: $FORM{'phone'}\n";
    print MAIL "Birthday: $FORM{'bday'}\n";
    print MAIL "------------------------------------------------------------\n";
    print MAIL "And this is what $FORM{'realname'} had to say:\n\n";
    print MAIL "$FORM{'message'}";
    print MAIL "\n------------------------------------------------------------\n";
    print MAIL "Web Site Rating: $FORM{'rating'}";
    print MAIL "\n------------------------------------------------------------\n";
    print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
    print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
    print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
    print MAIL "------------------------------------------------------------\n";
    close (MAIL);

    # Make the person feel good for writing to us

    # ------------------------------------------------------------
    # subroutine blank_response
    sub blank_response
    {

    print "<html>\n";
    print "<Head><Title>Incomplete Comment Form</Title></Head>";
    print "<Body><H1>Incomplete Comment Form</H1>";
    print "<p>";
    print "The $_[0] field appears to be blank! ";
    print "Please finish filling out the form and re-submit your comments. ";
    print "</body></html>";
    exit;
    }

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    Your professor must be a very incompetent Perl programmer to have you use such an old and poorly written script.

    To check for syntax errors, execute it from the command line like this:
    D:\perl>perl -c Form-mail.pl
    Form-mail.pl syntax OK
    While being extremely poorly written, it doesn't have any syntax errors.

    What response are you getting that lead you to believe that it had syntax errors?
    Last edited by FishMonger; 07-29-2012 at 03:20 PM.

  • #3
    Regular Coder
    Join Date
    Jun 2012
    Location
    Near Chicago, USA
    Posts
    123
    Thanks
    7
    Thanked 19 Times in 19 Posts
    Internal Server Error could be because of incorrect permissions (755 on Unix/Linux) on the script file. Also if line endings are incorrect (\n on Unix/Linux).

    Don't have Windows server experience, so can't speak for its requirements.

    Will
    Numerology API for apps - Facebook, iPad, mobile phones. No charge to use API. [info]


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •