PDA

View Full Version : formmail cgi file


trg
06-30-2005, 11:40 PM
I am trying to create a simple web form which when the submit button is pressed the info from the form goes to my email address. I am using a formmail.cgi file. It appears to be working on the internet, however I never receive the email!

This is what I have in the recipients section my cgi file (besides the other coding that is used):

@recipients = &fill_recipients(@referers);

and my form looks like this:

<form method="POST" action="../cgi-bin/FormMail.cgi">
<input name="recipient" type="hidden" value="myemail@my.domain">
<p>*Name: <input type="text" name="name">
<p>
<input type="submit" value="Submit">

Can someone tell me what I might be doing wrong?? Thanks!

rwedge
07-01-2005, 12:04 AM
If that's Matts script I would dump it for NMS (http://nms-cgi.sourceforge.net/formmail_compat-3.14c1/FormMail.pl) and this expample (http://nms-cgi.sourceforge.net/formmail_compat-3.14c1/EXAMPLES) page should help you set it up.

In your example form, your email address is up for grabs.

You should also rename FormMail.pl to something else as it will be less easy to find.

trg
07-01-2005, 12:11 AM
What does the first line mean? #!/usr/bin/perl -wT
Do I need to change the path of that? And can I rename the extension of the file to .cgi? My administrator said it has to be cgi.

Thanks!

mlseim
07-01-2005, 12:39 AM
That top line is called the "shebang". And since your script ran without error, it must be correct.

You can name the extension .cgi or .pl ... actually, you may be able to name it anything (depends on your webhost).

You might want to change the name "formmail" to something else too.
Maybe: "for_mail" or something that spamming robots can't figure out.
They will search for common form processor names and hammer them.

As rwedge said, the original Matt's script has some security issues and
was re-written in a new version (as he indicates).

... also

Hard-code your email address and subject in your script. Only let the
visitor's (sender's) address come through along with the message.

trg
07-05-2005, 08:01 PM
If I rename my form mail file to something else, say mailform.cgi do I also need to rename the first line (the shebang) #!/usr/bin/perl -wT ?

Then on my html page, do I call this mailform.cgi in my form? Thanks!!

rwedge
07-05-2005, 08:44 PM
You do not need to change the shebang line and yes, you can rename the Perl script to mailform.cgi and then make the html form target the new name mailform.cgi

trg
07-05-2005, 11:02 PM
Now that I am trying to use the script from NMS (http://nms-cgi.sourceforge.net/formmail_compat-3.14c1/FormMail.pl) and thought I had made the changes I need, but now I am receiving a HTTP 500 error saying the Page cannot be displayed. I am attaching the first couple of pages to the cgi file and also here is the code on my form. Any advise? Thanks!

<tr>
<td>&nbsp;</td>
<td><form method="POST" action="../cgi-bin/MailForm.cgi">
<!--<input name="recipient" type="hidden" value="tgomez@waterboards.ca.gov"> -->
<!-- <input name="realname" type="hidden" value="tgomez@waterboards.ca.gov"> -->
<p>*Name:
<input type="text" name="name">
</p>
<p>
<input type="submit" value="Submit">
</p>
<p>&nbsp; </p>
<p>&nbsp; </p>
</form></td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>

rwedge
07-06-2005, 07:13 AM
I don't see any problems with your added changes to the script. Make sure the permissions on the script are set to 755. Perl scripts must be uploaded in ascii, not binary mode.

Debug is set to 1 so it should output error messages to the browser. Since the script dies so quickly, maybe one of the two above could be the cause.

When you get it working and put it to use, set Debug to 0 for security.

trg
07-08-2005, 05:55 PM
How do I set the permissions for the cgi file? And how do I know for sure that it has been saved as an asii file? I opened it in notepad and did a save as and gave it the .cgi extension.
Does it matter what kind of mail server we are using? We are using Novel Groupwise?

Sorry I am such a rookie! :confused:

Thanks for your help!

FishMonger
07-08-2005, 06:40 PM
What OS is the cgi script running on; Windows or Linux/UNIX? If it's Windows, the problem may be Windows is having a problem with running in taint mode.

Test Example:
C:\>type test.pl
#!/usr/bin/perl -wT

print "running in taint mode\n";

C:\>test.pl
"-T" is on the #! line, it must also be used on the command line at C:\test.pl line 1.

C:\>perl -T test.pl
running in taint mode

trg
07-09-2005, 12:07 AM
It's running on a unix server. Should I make a change to the script? Thanks.

rwedge
07-09-2005, 04:43 AM
You should not have to change anything for Unix. Notepad is ok to edit. It can open an unknown file type in binary , line breaks appear as boxes, code is on one line. but you would see is wasn't right.

How do you save the file to your host?

If you use an ftp program, be sure to use ascii mode. Most ftp programs have an option to chmod a file. For instance, with WS_FTP you right click on the file in the host file listings and scroll to the chmod option.

If you are using a cpanel file manager and copy and pasting the script into a textarea, make sure there are no empty lines before the script and no spaces before the #!/usr/bin/perl line. There is an option in the cpanel to set the permissions on the file.

You can also chmod a file on Unix with:

#!/usr/bin/perl
$perms = `chmod 0755, 'MailForm.cgi'`;
print "Content-type: text/plain\n\n";
($perms)? print 'failed to set perms': print 'success';

This would be ran in the same directory as MailForm.cgi.

trg
07-27-2005, 10:45 PM
Thanks for all your help! We finally figured out we didn't have enough ../../'s to point to the sendmail file. Apparently it was real deep on the server....
Live and Learn! :thumbsup: