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

Obviously I have come to the right place. This hand rolled script was working fine until I changed a client's site from a single page presentation to a <frameset>. (I'm not looking for a lecture; it just gives him the presentation he wants.) Now his "Contact Us" form fields are parsed with this particular script:
#!/usr/bin/perl -w use strict; use warnings; use CGI; my $query = new CGI; print "Content-type:text/html\n\n"; my $to='clients email'; my $from='clients email'; my $subject='Contact Request'; my $name = $query->param('name'); my $email = $query->param('email'); my $address1 = $query->param('address1'); my $address2 = $query->param('address2'); my $city = $query->param('city'); my $state = $query->param('state'); my $zip = $query->param('zip'); my $country = $query->param('country'); my $homephone = $query->param('homephone'); my $workphone = $query->param('workphone'); my $business = $query->param('business'); my $goals = $query->param('goals'); my $comments = $query->param('comments'); open(MAIL, "|/usr/sbin/sendmail -t"); print MAIL "To: $to\n"; print MAIL "From: $from\n"; print MAIL "Subject: $subject\n\n"; print MAIL "Name: $name\n"; print MAIL "EMail: $email\n"; print MAIL "Address_line_1: $address1\n"; print MAIL "Address_line_2: $address2\n"; print MAIL "City: $city\n"; print MAIL "State: $state\n"; print MAIL "Zip: $zip\n"; print MAIL "Country: $country\n"; print MAIL "Home_Phone: $homephone\n"; print MAIL "Work_Phone: $workphone\n"; print MAIL "Type_of_Business: $business\n"; print MAIL "Goals: $goals\n"; print MAIL "Comments: $comments\n"; close(MAIL); print "<html><head><title>Client's Site</title> <link href=http://clients URL CSS/css/shell3.css rel=stylesheet type=t +ext/css> </head>\n<body>\n"; print "<HR size=2>"; print "<CENTER><H1><U>Message Received!!!</U><P> YOUR business is VERY important to Us! <U>We will respond as soon as w +e can.</U></H1></CENTER>"; print "<P>"; print "<center><a href=http://clientsURL/index.html><I>PRO WEB Design< +/I> Home Page</a></center>"; print "<hr size=2>"; print "</body></html>";
I've run it through my trusty copy of Perl Edit and it says the syntax is fine; no errors generated. BUT when I run this form from his site, it doesn't send the information into his email box like it had previously done before.
Also, the user's input is sent via ssl. Any suggestions...Forgive for takinkg to Send Mail directly. Sincerely Trying but Lost!

Replies are listed 'Best First'.
Re: Hand Rolled CGI
by virtualsue (Vicar) on May 07, 2004 at 10:44 UTC
    Is it just the bit which talks to sendmail that is broken? Do you see the HTML afterwards? If not, then I would guess this script is not being executed, and the form action on your 'Contact Us' page is bogus.

    If this script is definitely being executed, the next thing to suspect is the attempt to pipe info to sendmail. You don't check the open or close for errors, which would give you some hints if those operations are failing for some reason. If either operation fails, particularly the open, then naturally there will be no email sent.

    open(MAIL, "|/usr/sbin/sendmail -t") or die "Ack! Failed to open pipe to sendmail: $!";
    For debugging purposes, you can have the error displayed to the browser if you add

    use CGI::Carp qw(fatalsToBrowser);

    to the top of your script.

Re: Hand Rolled CGI
by bradcathey (Prior) on May 07, 2004 at 11:45 UTC

    This doesn't really answer your ultimate question, but do consider virtualsue's suggestion to use use CGI::Carp qw(fatalsToBrowser);, often a lifesaver.

    Also consider using Mail::Sendmail or some other alternatives to the plain wrapper sendmail. The former is a bit more secure and allows you to do cleaner coding, as in:

    my %mail = ( To => $to, From => $from, #Bcc => , #Cc => , Subject => $subject, Message => " Name = $name\n Email = $email\n etc.... "); sendmail(%mail) or die $Mail::Sendmail::error;

    All the best


    —Brad
    "A little yeast leavens the whole dough."
      Note that virtualsue's suggestion was to use CGI::Carp qw(fatalsToBrowser); for debugging. That should be for debugging only!

      You do not want to leave that line in pages in production since the debugging information provided can help an attacker "debug" how to effectively compromise your script.

        Absolutely, tilly, I never meant to imply that the line stay in for production code. But thanks for pointing that out.

        —Brad
        "A little yeast leavens the whole dough."
Re: Hand Rolled CGI
by gloryhack (Deacon) on May 07, 2004 at 21:27 UTC
    First things first: Look in the HTTP server error log, so you'll know whether or not your script is giving up a dying confession. Or do as knowledgable others have suggested, and make use of CGI::Carp.

    Second thing: Change:

    PrivoxyWindowOpen(MAIL, "|/usr/sbin/sendmail -t");

    to:

    if (PrivoxyWindowOpen(MAIL, "|/usr/sbin/sendmail -t")) { # print statements here close MAIL; } else { # error handling here; perhaps inform user. }

    This way, if there's a failure to open the pipe to sendmail, it'll be able to tell you (masquerading as a normal web user) about it.

    Depending upon whether you're using the real sendmail or another MTA's compatibility interface, you might need to adjust your arguments in the pipe open. Check the docs for the one you're actually using.

Re: Hand Rolled CGI
by Lost (Novice) on May 07, 2004 at 23:11 UTC
    Maybe I need to explain a little further:
    Once the site's visitor enters text into certain fields on the form, (i.e.-Name, Address, Email, City, State,Zip...etc etc)and presses the "Submit" button, the script is executed, the "Request Received" receipt page comes up as it should to let the visitor know the form worked properly, my client receives the request in his Inbox as he should, but when my client opens the email, the info his visitor entered into the form is not there. Simply put, the text was not parsed from the form.
    I did add the line:
    Use CGI::Carp qw(fatalsToBrowser); and the only error that came up was as follows:
    Can't locate object method "new" via package "CGI" (perhaps you forgot to load "CGI"?) at /ssl/formaction.pl line 6.
    Now to the HTTP server log. When I check the syntax on my trusty copy of Perl Edit, it says the syntax is perfect; no errors are generated. BUT when I run Perl Checker on his commercial web hosting's server (Yahoo Small Business) the all to familiar comes up in the .log: Use of uninitialized value in concatenation on lines 34-45... (which ironically are the parsed fields) but my name/value pairs are fine. Again, this script was working fine prior, so I'm wondering if there was something very simple I may have accidently deleted from the script I'm just not seeing. Thanks again for all your past help and upcoming suggestions. Sincerely,
    Lost (Shawn)
      It'd be strange and unusual, but it sounds a lot like CGI.pm isn't installed, or isn't in your path.