Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] parse..

Expand Messages
  • Greg Webster
    ... A very simple, but completely workable form mailer. #!/bin/perl############################################################################## # Form Mailer
    Message 1 of 3 , May 22, 2000
    • 0 Attachment
      On Mon, 22 May 2000, you wrote:
      > Could someone give me some standard and reliable code that I could use to
      > parse a form (or get the CGI)?

      A very simple, but completely workable form mailer.


      #!/bin/perl##############################################################################
      # Form Mailer by Greg Webster (c) 1998-2000
      # Removal of this notice constitutes violation of copyright
      ##############################################################################

      # Location of sendmail.
      $send_mail_loc = "/usr/lib/sendmail -t";

      # Enter required fields in the form of ('field1','field2'...). If none are
      # required, change this line to @required = ();
      @required = ();

      $formemail = "email\@...";

      ##############################################################################
      # Get onto the real work
      ##############################################################################

      ############################################
      # Split form values into readable form
      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;
      }

      ############################################
      # Check for required fields
      foreach $check(@required)
      {
      unless ($FORM{$check})
      {
      print "Content-type: text/html\n\n";
      print "<html><body><h1>Missing Required Fields</h1><br>\n";
      print "Please hit your <b>back</b> button and fill in the $check field.\n";
      print "</body></html>\n";
      exit;
      }
      }

      open (MAIL,"|$send_mail_loc") || die("Could not open $send_mail_loc");
      print MAIL "To: $formemail\n";
      print MAIL "From: signup\@...\n";
      print MAIL "Subject: $FORM{'subject'}\n";
      print MAIL 'Please contact the person below. This email was automatically created via http://www.dowco.com/signup.'."\n";
      print MAIL "The following information has been submitted:\n\n";
      foreach $pair (@pairs)
      {
      ($name, $value) = split(/=/, $pair);
      $value =~ tr/+/ /;
      $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
      unless ($name eq "response" || $name eq "subject")
      {
      print MAIL "$name: $value\n";
      }
      }
      close MAIL;

      print "Content-type: text/html\n\n";
      print "<html><head><title>Thank you!</title></head>\n";
      print "<body><h1>Submission successful</h1><br>\n";
      print "Please click back to continue.\n";







      --
      <>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<>
      / \ GREG WEBSTER - greg@... / \/ \/ \
      \ / http://www.geekrights.org \ /\ /\ /
      <>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<><>-<>
    Your message has been successfully submitted and would be delivered to recipients shortly.