ehorne has asked for the wisdom of the Perl Monks concerning the following question:

I am new to perl and trying to create a script to send information from a form to my email. I am checking my script using the cmd prompt and am getting the error: use of uninitialized value $ENV{"REQUEST_MEHTOD"} in string eq in feedback line 6. Seems like a simple problem, but I am stuck. The first part of my script below:

Thank you!

#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); # The following accepts the data from the form and splits it into its +component parts 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; } # Then sends the email open (MESSAGE,"| /usr/sbin/sendmail -t"); print MESSAGE "To: design\@erinhorne.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 "Message: $FORM{message}\n\n"; print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n"; close (MESSAGE); }

Replies are listed 'Best First'.
Re: perl $ENV question
by moritz (Cardinal) on Aug 16, 2009 at 22:21 UTC
    First of all the error message doesn't match your code - it's misspelled in the error message - which one did you actually use? REQUEST_MEHTOD or REQUEST_METHOD?

    Second, I'd recommend the request_method sub/method from CGI.

    Third, please don't send emails like that - it can easily be abused for sending spam. Use something like MIME::Lite instead.

      Thank you. Yes, I accidentally misspelled the error in my post.
      Also, I don't know what MIME:Lite is, but I will look into it.
      Thanks!
Re: perl $ENV question
by zwon (Abbot) on Aug 16, 2009 at 22:21 UTC

    That's because environment variable REQUEST_METHOD isn't defined. You can define it in your shell, or just add a check:

    if ($ENV{REQUEST_METHOD} and $ENV{'REQUEST_METHOD'} eq 'POST') {