in reply to Getting response from a form

Sounds like time to debug. First, I would run it from the command line. If you're using CGI.pm (and you ought to be using it), you can execute your script and it will prompt you for name=value parameters (just like you'd see in the GET request). Next, I would print each of those out (print $q->param{$_) foreach keys $q->param(); or something like that), just to make sure you're grabbing the right data. Then, I would comment out the calls to your mailer, and simply print out the e-mail you'd be sending. If it's blank there, your error is earlier in the script. If it's not blank, your error is in the interface to your mailer.

That's just general troubleshooting. Perhaps if you posted the relevant parts of your program, we can be more specific.

Replies are listed 'Best First'.
RE: Re: Getting response from a form
by btrott (Parson) on Mar 24, 2000 at 07:20 UTC
    Actually, the param method returns a list of the parameter names, not a hash.

    So you should just use

    for my $param ($q->param) { print $param, " => ", $q->param($param), "\n"; }
RE: Re: Getting response from a form
by Anonymous Monk on Mar 24, 2000 at 19:08 UTC
    chromatic, This is the script. Do you see anything that doesn't look right? Honestly, I don't have a clue. #!/usr/local/bin/perl $cgi_lib'maxdata = 131072; $cgi_lib'writefiles = 0; $cgi_lib'filepre = "cgi-lib"; $cgi_lib'bufsize = 8192; $cgi_lib'maxbound = 100; $cgi_lib'headerout = 0; print &PrintHeader; &ReadParse; $mailprog = '/usr/lib/sendmail'; $address = 'bjenkins@holstongases.com'; open (MAIL, "|$mailprog $address\n") || die "Can't open $mailprog!\n"; print MAIL "$in{'company_name'}\n"; print MAIL "$in{'contact'}\n"; print MAIL "$in{'phone'}\n"; print MAIL "$in{'fax'}\n"; print MAIL "$in{'email'}\n"; print MAIL "$in{'PO_number'}\n"; print MAIL "$in{'when_required'}\n"; print MAIL "$in{'order_qty1'}\n"; print MAIL "$in{'order_item1'}\n"; print MAIL "$in{'order_desc1'}\n"; print MAIL "$in{'order_price1'}\n"; print MAIL "$in{'order_total1'}\n"; print MAIL "$in{'order_qty2'}\n"; print MAIL "$in{'order_item2'}\n"; print MAIL "$in{'order_desc2'}\n"; print MAIL "$in{'order_price2'}\n"; print MAIL "$in{'order_total2'}\n"; print MAIL "$in{'order_qty3'}\n"; print MAIL "$in{'order_item3'}\n"; print MAIL "$in{'order_desc3'}\n"; print MAIL "$in{'order_price3'}\n"; print MAIL "$in{'order_total3'}\n"; print MAIL "$in{'order_qty4'}\n"; print MAIL "$in{'order_item4'}\n"; print MAIL "$in{'order_desc4'}\n"; print MAIL "$in{'order_price4'}\n"; print MAIL "$in{'order_total4'}\n"; print MAIL "$in{'order_qty5'}\n"; print MAIL "$in{'order_item5'}\n"; print MAIL "$in{'order_desc5'}\n"; print MAIL "$in{'order_price5'}\n"; print MAIL "$in{'order_total5'}\n"; print MAIL "$in{'order_qty6'}\n"; print MAIL "$in{'order_item6'}\n"; print MAIL "$in{'order_desc6'}\n"; print MAIL "$in{'order_price6'}\n"; print MAIL "$in{'order_total6'}\n"; print MAIL "$in{'order_qty7'}\n"; print MAIL "$in{'order_item7'}\n"; print MAIL "$in{'order_desc7'}\n"; print MAIL "$in{'order_price7'}\n"; print MAIL "$in{'order_total7'}\n"; print MAIL "$in{'order_qty8'}\n"; print MAIL "$in{'order_item8'}\n"; print MAIL "$in{'order_desc8'}\n"; print MAIL "$in{'order_price8'}\n"; print MAIL "$in{'order_total8'}\n"; print MAIL "$in{'order_qty9'}\n"; print MAIL "$in{'order_item9'}\n"; print MAIL "$in{'order_desc9'}\n"; print MAIL "$in{'order_price9'}\n"; print MAIL "$in{'order_total9'}\n"; print MAIL "$in{'order_qty10'}\n"; print MAIL "$in{'order_item10'}\n"; print MAIL "$in{'order_desc10'}\n"; print MAIL "$in{'order_price10'}\n"; print MAIL "$in{'order_total10'}\n"; print MAIL "$in{'order_qty11'}\n"; print MAIL "$in{'order_item11'}\n"; print MAIL "$in{'order_desc11'}\n"; print MAIL "$in{'order_price11'}\n"; print MAIL "$in{'order_total11'}\n"; print MAIL "$in{'order_qty12'}\n"; print MAIL "$in{'order_item12'}\n"; print MAIL "$in{'order_desc12'}\n"; print MAIL "$in{'order_price12'}\n"; print MAIL "$in{'order_total12'}\n"; print MAIL "$in{'order_qty13'}\n"; print MAIL "$in{'order_item13'}\n"; print MAIL "$in{'order_desc13'}\n"; print MAIL "$in{'order_price13'}\n"; print MAIL "$in{'order_total13'}\n"; print MAIL "$in{'order_qty14'}\n"; print MAIL "$in{'order_item14'}\n"; print MAIL "$in{'order_desc14'}\n"; print MAIL "$in{'order_price14'}\n"; print MAIL "$in{'order_total14'}\n"; print MAIL "$in{'order_qty15'}\n"; print MAIL "$in{'order_item15'}\n"; print MAIL "$in{'order_desc15'}\n"; print MAIL "$in{'order_price15'}\n"; print MAIL "$in{'order_total15'}\n"; close(MAIL); sub ReadParse { local ($method, $query, @keypairs, $keyvalue, $key, $value); $method = $ENV{'REQUEST_METHOD'}; if ($method eq "GET") { $query = $ENV{'QUERY_STRING'}; } elsif ($method eq "POST") { read (STDIN, $query, $ENV{'CONTENT_LENGTH'}); } @keypairs = split(/&/,$query); foreach $keyvalue (@keypairs) { ($key,$value) = split(/=/,$keyvalue); $key =~ tr/+/ /; $key =~ s/%(\dA-Fa-f\dA-Fa-f)/pack("C",hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%(\dA-Fa-f\dA-Fa-f)/pack("C",hex($1))/eg; $value =~ s/\r\n+$//; if (defined($in{$key})) { $in{$key} = join("\0",$in{$key},$value); } else { $in{$key} = $value; } } } sub PrintHeader { return "Content-type: text/html\n <html> <title><holstongases.com></title> <body bgcolor=teal text=black link=red vlink=red>
    Holstongases.com



    Thank You for Your Order. We Appreciate Your Business



    This Order Will Be Confirmed by E-mail or Fax within 24HRS.

    "; }
      Aside from the cgi_lib stuff (move to CGI.pm as soon as you can), I'm not sure you're opening sendmail right. perlfaq9 gives the example code:
      open(SENDMAIL, "|/usr/lib/sendmail -oi -t -odq") or die "Can't fork for sendmail: $!\n"; print SENDMAIL <<"EOF"; From: User Originating Mail <me\@host> To: Final Destination <you\@otherhost> Subject: A relevant subject line Body of the message goes here after the blank line in as many lines as you like. EOF close(SENDMAIL) or warn "sendmail didn't close nicely";
      I would change the To: line to include your address. Also, using a here doc makes your code look much neater. I'd also rethink the value of putting every parameter from the order page in one hash -- if you use a couple of different scalars and one big array, you won't have to go through that long section in the middle accessing each hash key directly. Specifically, make an array for orders, and join the the quantity, item, description, price, and total in each slot. Then just do a foreach loop over that array, and print each line to the MAIL filehandle.

      To debug this (as I'm not sure the ReadParse() subroutine is doing what you think it should), comment out the lines opening sendmail, and open the MAIL filehandle to print to a file somewhere, then run the program again. If you get what you'd normally expect in the e-mail, your problem is in the way you're opening sendmail. If you don't get what you expect in the file, you're probably not decoding the QUERY_STRING the way you expect. (That join statement just looks funny to me....)