Tech Support Topics

Sphynx Server CGI

Simple Form Handling Script for Your Virtual Server

formmail.pl


  1. Installation
  2. Automated Reply


Installation

To install the simple version of formmail, you need to install the formmail.pl script in your cgi-bin directory, then make the script executable. If you like you can hack the script a little to customize the return page or other variables. To install the archived version, establish a telnet session with your Virtual Server and do the following:

  1. Copy the formmail.pl script into your cgi-bin. Type the following instructions at the shell prompt:
      % cp /usr/local/contrib/formmail.pl ~/www/cgi-bin
      % chmod 755 ~/www/cgi-bin/formmail.pl
    

  2. Now, just create a fill-out form, the contents of which you would likemailed to some Internet email address. The form should include the follwing fields:

    For example, the HTML source for your form may look like this:

      <form method="POST" action="/cgi-bin/formmail.pl">
      <input type="hidden" name="recipient" value="get-info@yourdomain.com">
      <input type="hidden" name="subject" value="Send Me Info">
      Please Enter Your Name:<br>
      <input name="realname" size="40">
      <p>
      Enter Your Email Address:<br>
      <input name="username" size="40">
      <p>
      Enter your location:<br>
      <input name="hometown" size="40">
      <p>
      .
      .
      .
      <input type="submit" value="Submit">
      <input type="reset" value="Reset">
      </form>
    


Automated Reply

One way to modify the script is to include an autoresponder that emails the user a response after he or she submits the form. To do this append something like the following to the bottom of the formmail.pl script.
  # open a message to the remote client
  open (MAIL, "|$mailprog $FORM{'username'}") || die "Can't open $mailprog!\n";
  print MAIL "To: $FORM{'username'} ($FORM{'realname'})\n";
  print MAIL "Reply-To: $FORM{'recipient'}\n";
  print MAIL "From: $FORM{'recipient'}\n";
  print MAIL "Subject: $FORM{'subject'}\n\n";

  # write out a customized response to the mail message 
  print MAIL "We have received your message and are delighted";
  print MAIL "you have requested information about our products.";
  print MAIL "Here is the information you requested - ";
  print MAIL "Product 1. - info about product 1";
  print MAIL "Product 2. - info about product 2";
  print MAIL "Product 3. - info about product 3";
  print MAIL "Product 4. - info about product 4";
  print MAIL "Product 5. - info about product 5";
  print MAIL "Yours truly, John Doe, sales rep.";

  # close the message
  close (MAIL);

Please Note: If you do use an autoresponder addition to the script, then the resulting script will be useable only by the form page owner who wants to reply with this particular autoreply.
One possible solution to this problem is to use one formmail.pl script without autoreply for everyone on your server to submit their forms to, and several preconfigured with certain autoreplies. The secret is to name each script a different name (formmail.pl, formmail-1.pl, formmail-2.pl, etc.) and upload each to your cgi-bin and then make them executable with chmod.



HOME | SITE HOSTING | VIRTUAL SERVERS | PAGE DESIGN | FAQ | ORDER | TECH SUPPORT


Copyright © 1996, Sphynx Web Solutions. All rights reserved. All brand names and product names used on these web pages are trademarks, or trade names of their respective holders. Direct questions or comments to webmaster@sphynx.com.