This error usually occurs when the path specified in the HTML which calls the script is incorrect.
<FORM METHOD="POST" ACTION="formmail.pl">
The easiest method to find the correct path takes two steps:
1) In your web browser, try to browse to the script directly. For example, type the URL "http://www.domain.com/cgi-bin/formmail.pl". If you continue to receive the same error, first check your capitalization (UNIX webservers are case-sensitive), then try other locations. You'll know you've reached the right location when you either receive an Internal Server Error (instead of the File Not Found Error), or you see the FormMail banner which looks like this:
Copyright 1995 - 1997 Matt Wright
Version 1.6 - Released May 02, 1997
A Free Product of
Matt's Script Archive, Inc.
2) Once you've located the correct spot, change the FORM tag to reflect the full path to the script. There's much less margin for error that way. For example:
<FORM METHOD="POST" ACTION="http://www.
This error has a multitude of causes, so I'll go through them one by one, in the order of frequency of their occurrence:
1. The Perl script was uploaded as Binary instead of ASCII, or was created with a Windows-based editor
The easiest way to verify that this is the case is to examine the code of your script on the webserver from a shell prompt using the UNIX editor vi. If the script was uploaded as binary, or if the script was edited using a Windows-based application, such as Notepad.exe, you'll see control characters (denoted by a carat ^ and a letter on most systems) scattered throughout the code. For example:
# FormMail Version 1.6 #^M
# Copyright 1995-1997 Matt Wright email@example.com #^M
# Created 06/09/95 Last Modified 05/02/97 #^M
# Matt's Script Archive, Inc.: http://www.worldwidemart.com/scripts/ #^M
Resolution: Re-upload the script, taking care to specify ASCII mode in your FTP client. From command-line FTP, typing ascii and pressing Enter will switch you to ASCII mode. Alternatively, the following vi command will clean the file of the carriage returns:
:1,$ s/control-V control-M//g
On the vi command prompt, if you entered the command precisely as described, the text should actually appear as follows, before you press
2. Incorrect path to the Perl executable in the first line
On some webservers, the Perl executable is not located in /usr/bin. If you have a shell account, you can find the correct path by typing which perl, where perl, or whereis perl. If you do not have the luxury of a shell, or these commands do not work, other common paths are /usr/local/bin/perl and /bin/perl.
Once you've found the correct path, simply change the first line of the script to reflect the correct path:
3. Incorrect path to sendmail
Follow the same instructions as above to locate the sendmail executable. The line where the sendmail path is specified looks like this:
# $mailprog defines the location of your sendmail program on your unix #
# system. #
$mailprog = '/usr/lib/sendmail';
Other common paths are /usr/ucb/sendmail, /usr/bin/sendmail, and /usr/local/bin/sendmail.
4. Syntax error within the script code
Theoretically, if you downloaded the script correctly and uploaded it to your webserver correctly, you should never see this error. However it does occur, often because of a typo when editing some of the script variables.
Again, if you have a shell account, you're at a great advantage. Simply move into the directory where the script resides, and type ./formmail.pl (or whatever you've chosen to name the script when you uploaded it). If any errors occur during execution, they will be printed to the terminal, along with line numbers where the errors occurred. You should be able to track down the error from there. Be sure to check the lines preceding and after the line number given in case misexecution of those lines caused actual errors to occur in other lines.
Typical errors include failure to include a closing quotation mark, accidental deletion of the semicolon on a line, and a program line divided by a carriage return.
Of course, as a last resort, you can always re-upload a fresh copy of the script, eliminating any errors that may be present.
5. Permissions errors
Though permissions problems usually elicit the Forbidden error message, they occasionally generate an internal server error instead, especially if the permission problem is not with the script executable itself but with a "helper" file such as a data file or helper application.
Files that can cause this error for formmail.pl are perl, sendmail, and the HTML file specified in the redirect tag.
You can view permissions for files in the directory listing from command line FTP, or by issuing the ls -al command from a shell. Typical output looks like this:
2 mmussel user 4096 Feb 21 16:24 .
4 mmussel user 4096 Nov 18 11:35 ..
1 mmussel aplus 0 Feb 21 16:24 data.db
1 mmussel user 1563 Nov 18 12:15 env.cgi
1 mmussel aplus 24261 Feb 21 16:24 formmail.pl
1 mmussel user 74 Nov 18 11:52 test.pl
As a general rule, use 777 (
-rwxrwxrwx)for writable data files and 755 (
-rwxr-xr-x)for executables, other files, and the cgi-bin directory itself. Permissions are changed via the chmod 755 filename command from a shell or command line FTP. Some FTP clients also allow you to change file permissions. If you deal with CGI frequently, it is higly suggested that you find an FTP client that supports changing permissions.
This error has two possible causes:
1. Permissions errors
See B.5 above for instructions on diagnosing and repairing file and directory permissions errors.
2. Domain or IP address not specified in referers array
Formmail.pl contains a variable entitled referers, which checks to make sure that only the forms which are on your web account are permitted to call your script. This prevents someone from using your bandwidth for their feedback/order forms. Unfortunately, if not configured correctly, the variable will deny script calls from your own website, as well.
The referers array should contain all domain names or IP addresses used by your website. It doesn't hurt to specify domains and IP addresses, to be safe.
A properly configured referer line would appear as follows:
# @referers allows forms to be located only on servers which are defined #
# in this field. This security fix from the last version which allowed #
# anyone on any server to use your FormMail script on their web site. #
@referers = ('mydomain.com','172.16.53.19');
Watch out for the quotes and commas; if they are accidentally deleted or misplaced, you will receive errors as well.
This error is far less common than the other errors, and is often generated as an alternative to some incidences of the Internal Server Error by some server/browser combinations. Typical causes for this error are as follows:
1. The Perl script was uploaded as Binary instead of ASCII
2. Incorrect path to the Perl executable in the first line
3. Syntax error within the script code
As all of these have been previously described, please see the corresponding heading above for diagnosis and correction.