WillMaster Possibillites Logo EzineSeek Award
Installing Multiple Copies of a Script
by
William "Will" Bontrager

Permission is granted to reprint this article in its entirety, provided no reprints are sent in conjunction with unsolicited bulk email, provided no fee or other value is exchanged, provided no changes are made to the article, and provided the author's name, signature lines, and copyright line are printed with the article; except you may change the article's title.

If you want to be notified every time a certain script on your site is used, here is how to do it. (Not applicable to NT servers, only UNIX/Linux. Few NT's can use the sendmail mailing code presented here.)

  1. Download your working script as ASCII/plain text.
     
  2. Make a backup copy. If something should go wrong with your edits, you can restore your script with the backup.
     
  3. Load the script into an ASCII/plain word processor like NotePad or BBEdit.
     
  4. The first line of Perl scripts begin with a sharp symbol (also called "pound" or "hash"): #

    Sometimes several subsequent lines also begin with the sharp symbol.

    Find the first line in the script that does not begin with a sharp symbol. At that point, insert the following 16 lines:
    open MYaltMAIL,"|/path/to/sendmail -t";
    print MYaltMAIL <<EndOfMyAltMAIL;
    To: me\@domain.com
    Subject: Customize subject line
    
    Hi,
    
    I come from $0
    
    This is worth lots of \$'s!
    
    Sincerely,
    
    Me
    EndOfMyAltMAIL
    close MYaltMAIL;
    
    Lines three through fifteen of the code may have no left margin. For the first, second, and last lines, a left margin is optional.
     
  5. On the first line of the code, modify the directory path to sendmail (keep the -t) or to qmail for your server. Keep the vertical bar character: |

    (If you don't know the directory path to your sendmail, your hosting company's tech support should be able to tell you. Or, you can use Master Pre-Installation Tester from http://willmaster.com/master/pit/ to help find it.)
     
  6. On the third line of the code, customize the To: email addresses.
     
  7. On the fourth line of the code, customize the Subject: text.
     
  8. The first blank line must follow the Subject: line (that first blank line separates the email header from the body content).
     
  9. On lines six through twelve, customize the body content to suit. (Leave the line containing only "EndOfMyAltMAIL" as it is, on a line by itself, no left margin, and no punctuation.)

    If you would like to insert some identifying information, you can use the indicated variables:
     
    • Type $0 (that's a digit zero, not a letter O) where you want the name of the script to appear.
       
    • Type $ENV{HTTP_REFERER} where you want the URL of the referrer, which would probably be the URL of the form being used.
       
    • Type $ENV{REMOTE_ADDR} where you want the user's IP address.
       
    Any of the above identifying variables can also be used in the Subject: line, if you wish.
     
  10. "@" symbols must be escaped with a backward-slash: \
     
  11. Unless they're used as the first character of a variable name (like the identifying variables in step 9), "$" symbols must be escaped with a backward-slash: \
     
  12. Header lines From:, Cc:, and/or Bcc: may be specified. Put them below the line beginning with "print" and above the first blank line. Between the To: and Subject: header lines would be good. Example:
    To: me\@domain.com
    From: fromname\@domain.com
    Cc: name2\@domain.com
    Bcc: name3\@domain.com
    Subject: Customize subject line
    
  13. Upload the modified script as ASCII/plain text.
     
  14. Test it.
     
  15. If the script works but you get no mail, either
     
    • the directory path to sendmail is incorrect,
       
    • the To: address is wrong, or
       
    • (if the To: address is to the same domain where sendmail is installed) your sendmail might be refusing to send mail to its own domain.
       
    If you suspect the latter (only a few sendmail installations are configured this way), get an email address outside your domain, such as from http://usa.net or http://hotmail.com, and try again. If it still doesn't send mail, check the other two points. The reason is almost certain to be one of the three points mentioned.
     
  16. If the script now gives you "Internal Server Error" or "Premature End Of Script Header" errors, use the points listed at http://MasterCGI.com/faq/ to debug.
     

Now, you are notified every time your script is used :)

Copyright 2001 William Bontrager
Programmer/Publisher, "WillMaster Possibilities" ezine
http://willmaster.com/possibilities/
subscribe-possibilities@willmaster.com
Business Home Page: http://willmaster.com/