Forum Moderators: coopster & phranque

Message Too Old, No Replies

Problem with sendmail form using FormMail.pl

I get an error when testing the form on a site I've created.

         

iainbunt

3:50 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



I've created a form on a site I've been doing, but when you submit the form the following message comes up:

"Method Not Allowed
The requested method POST is not allowed for the URL /cgi-bin/FormMail.pl."

I've checked the code at the start of my form and that on the FormMail.pl script and they match what I've used on a previous (successful site). Has anyone any suggestions what's wrong?

Iain

perl_diver

7:09 pm on Apr 23, 2008 (gmt 0)

10+ Year Member



Could be the server is not setup correctly or they just do not want people using "post". Any tech support you can ask? You can try setting the forms method to "get" just to test if that is allowed, of course it is not as flexible as "post" but at least you can check.

Keep in mind this probably has nothing to do with perl and is not really a CGI issue either, more than likely it is a server problem.

IanKelley

1:09 am on Apr 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It's possible that this is a security hack specifically for FormMail.pl as a result of all the exploits in the old script commonly called by that name. Poor solution by your host if so.

Have you tried changing the name of the script to something completely different? mailhandler.cgi for example.

If that doesn't work and they are actually restricting POST requests to all perl scripts then don't even bother contacting them, switch hosts.

iainbunt

8:22 am on Apr 24, 2008 (gmt 0)

10+ Year Member



The tech support just say they can't give support on scripts. I've tried renaming the file as suggested and that's not helped.

I'm beginning to think it is the server, however I have used a similar form with them in the past without a problem. I tried changing POST to GET and got the following:

Forbidden
You don't have permission to access /cgi-bin/mailhandler.cgi on this server.

Iain

IanKelley

7:01 pm on Apr 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yep switch hosts.

I say this so flippantly because these days there are endless good web hosts out there with fair prices. There's just no reason to stay with one that tries to limit your options or is unwilling to work with you when there are problems.

perl_diver

7:51 am on Apr 25, 2008 (gmt 0)

10+ Year Member



Before switching, are the perl file permissions set correctly? 755 is pretty common. Although the wrong permissions would generally not result in the first error message you posted.

iainbunt

8:24 am on Apr 29, 2008 (gmt 0)

10+ Year Member



A little bit of ignorance on my part here, where do I set the perl file permissions?

perl_diver

3:40 pm on Apr 29, 2008 (gmt 0)

10+ Year Member



You can do that if there is a control panel that your webhost has installed for you to use, or you can can do it using an FTP client, or if you can log into the server via telnet you can do it that way although the first and second suggestions will probably be easiest for you. The technical term is CHMOD, so you may see that in the control panel or FTP client, either of which should have some help files or instructions that explain changing the file permissions/CHMOD.

iainbunt

9:20 am on Apr 30, 2008 (gmt 0)

10+ Year Member



Before I go down the wrong lines I thought it best if someone could check the code I've been using, this is the header for the form:

<form method="GET" action="http://www.example.co.uk/cgi-bin/mailhandler.cgi">
<input type="hidden" name="recipient" value="root@example.co.uk">
<input type="hidden" name="subject" value="Enquiry">
<input type="hidden" name="httpreferer" value="http://www.example.co.uk/enquiry.html">

Does this all seem right

[edited by: phranque at 3:18 pm (utc) on April 30, 2008]
[edit reason] examplified urls [/edit]

IanKelley

9:51 am on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You said the error was:

"Method Not Allowed The requested method POST is not allowed for the URL /cgi-bin/FormMail.pl."

The code you just posted is using GET. Do you get the same error message with it?

IanKelley

9:53 am on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As a side note:

<input type="hidden" name="recipient" value="root@example.co.uk">

Every spam bot on the net is going to slurp that email addy. You should consider hard coding it into the sendmail script.

[edited by: phranque at 3:18 pm (utc) on April 30, 2008]
[edit reason] examplified url [/edit]

iainbunt

10:20 am on Apr 30, 2008 (gmt 0)

10+ Year Member



yes, sorry I've been trying options to get it to work and they both have the same problem. As for the side note, this is something I'll look at.

perl_diver

4:06 pm on Apr 30, 2008 (gmt 0)

10+ Year Member



The form code is OK but it is not part of your current problem. The "Method not supported" error should be coming from the web server you are using. You can ask your web host if you are allowed to use forms and CGI scripts. But if they gave you a cgi-bin you would think it is allowed. Or did you create the cgi-bin folder yourself on the server? If you did that will more than likely not work.

iainbunt

8:55 am on May 1, 2008 (gmt 0)

10+ Year Member



They do allow scripts and they tell you to put them in a cgi-bin folder as I have. It's odd, we've done a few sites now with the same form system without a problem, but now myself and a colleague are both having the exact same problem. It's bewildering!

perl_diver

8:18 pm on May 1, 2008 (gmt 0)

10+ Year Member



Can you tell if the error is coming from the scipt or the server? Do you need to set some option in the script to allow POST or GET?

IanKelley

11:30 pm on May 1, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



"Method Not Allowed
The requested method POST is not allowed for the URL /cgi-bin/FormMail.pl."

That's a server error. Also he said that he tried both GET and POST.

The fact that you've used the script before and it worked, and that your associate is now having the same problem, clinches that it's something your host has done. Again most likely an amateur attempt at security.

It sounds like this is shared hosting correct? You don't have a dedicated server? Shared hosting is one of the most competitive industries on the internet, monthly prices are down to around $5-$10 (for a quality host mind you), don't waste time with a host gives you problems.

iainbunt

8:41 am on May 2, 2008 (gmt 0)

10+ Year Member



It is a shared host, and for everything else we've done with them they've been more than helpful as well as incredibly reliable. I'll bat this back to them, see if I get any result.

lexipixel

4:55 am on May 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Is FormMail.pl in the cgi-bin ?

Is the server sensitive? (e.g.- maybe lower-case "formmail.pl" will work)...

Simple test to know if the server will execute a perl script... put a basic "hello world" script in the cgi-bin where your non functioning script is -- if it will execute one script, it should run any... that will nail down the "is it the script or the server?" question.


#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<HTML><BODY><H1>Hello World</H1></BODY></HTML>\n";

If "Hello World" prints, it's your script or one of the parameters in your script.

If it does not print, it's the server or the permissions on the cgi-bin.

phranque

7:30 am on May 3, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



i still think it's configuration related and has to do with the script file in its environment.

what are the ownership and permissions on the file?

i would try renaming the script to formmail.cgi in case it doesn't let you use .pl files as cgi scripts.
it can't hurt.
it looks like you may have tried this but make sure to change the action attribute in the form tag to match the new script name.

it's also possible it doesn't like you directly accessing the cgi-bin directory - try using just ...action="formmail.cgi"... without domain and path information and see if it finds the script in cgi-bin.

[edited by: phranque at 10:19 am (utc) on May 3, 2008]

IanKelley

8:40 am on May 3, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The point here is that the nature of the error makes it obvious that it is caused by something on the server side beyond the OP's control.

I hate to beat a dead horse but:

"Method Not Allowed
The requested method POST is not allowed for the URL /cgi-bin/FormMail.pl."

and also

You don't have permission to access /cgi-bin/mailhandler.cgi on this server.

There is absolutely nothing you can do wrong with a perl script that will cause the first error on a correctly configured server.

The second error you could only re-create by CHOWNing the script which is impossible to do via either FTP or the control panel on shared hosting.

Is FormMail.pl in the cgi-bin ?

The OP mentioned that it was earlier in this thread and that his host told him to put it there.

Is the server sensitive? (e.g.- maybe lower-case "formmail.pl" will work)...

He tried changing the filename to an all lowercase name already, see above.

Simple test to know if the server will execute a perl script...

Again see above, and besides, the errors have nothing to do with whether or not perl can run.

I don't mean to nitpick (I know you're just trying to help) but I'd like to see the OP find a solution and that's not going to happen until his host either gives him a meaningful reply or changes the server config.

chorny

10:02 am on May 12, 2008 (gmt 0)

10+ Year Member


1. Check file permissions (try 777 - rwx for owner, group and all). It is done in ftp or scp client you use to upload files.

2. Look at error log from webserver

3. Check if correct name of program is being used. It must be in correct case.

4. Don't use <input type="hidden" name="recipient" - anybody will be able to replace this and send mail to anyone, this is frequently used by spammers. Matt scripts archive is very bad place to get reliable programs. Put recipient directly into program.

iainbunt

1:47 pm on May 12, 2008 (gmt 0)

10+ Year Member



I have had the cgi scripts reset by the host,I am now getting a totally different error: "Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@chippendale.co.uk and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log."

Does this change things. Also Chorny, what would you suggest instead of "<input type="hidden" name="recipient""

chorny

6:04 pm on May 12, 2008 (gmt 0)

10+ Year Member


Is this error only for this CGI program or for others also? In any case check error log from webserver. Also check that correct path to perl is in the first line.

iainbunt

4:02 pm on May 15, 2008 (gmt 0)

10+ Year Member



I've just tried using a different mail script and get the same "Internal Server Error" does this imply the problem is in my form code?

IanKelley

5:11 pm on May 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes that's generally a 500 error which is a problem with the script. Usually it means the permissions are wrong (should be 755).

If the permissions are correct then you can get more information about the script error by putting the following near the top of the script:

use CGI::Carp qw(fatalsToBrowser);

SteveWh

6:03 pm on May 15, 2008 (gmt 0)

10+ Year Member



Also check your .htaccess to make sure you aren't disallowing POST requests to that file (or that type of file).

phranque

8:20 pm on May 15, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



most importantly, whenever you have a 500 error you should check for clues in the server error log.

iainbunt

11:43 am on May 16, 2008 (gmt 0)

10+ Year Member



This is the error from the log file "[Thu May 15 16:57:47 2008] [error] [client 000.000.000.000 Premature end of script headers: /home/fhlinux149/c/example.co.uk/user/htdocs/cgi-bin/bizmail.cgi"

Any idea?

[edited by: phranque at 3:29 am (utc) on May 17, 2008]
[edit reason] examplified ip and url [/edit]

SteveWh

12:25 pm on May 16, 2008 (gmt 0)

10+ Year Member



The premature end of script headers is the same error I got a couple days ago when I'd neglected to set the file's permissions to 755. The default upload permissions are 644, which doesn't allow this executable file to execute.

So the permissions must be 755. (You can do that in cPanel.)
You must use POST, not GET.
Name the script to some name that does NOT have "form" or "mail" anywhere in the name. Some hosts will prohibit any script with a name like that.
For "action=", try a local path instead of absolute (eliminate the http: //...).

The fact that the host tech changed server settings and now you're getting a different error points to a server config issue rather than something wrong with the script.

In response to chorny's comment, if you're using Matt's original FormMail.pl program, switch to the NMS FormMail version available at SourceForge.

[edited by: SteveWh at 1:19 pm (utc) on May 16, 2008]

iainbunt

1:31 pm on May 16, 2008 (gmt 0)

10+ Year Member



Hi all, a big thanks for your help. I've now resolved the form. On another note if I want to have an email box and a confirm email box, how do I set up the form to ensure the boxes match?
This 35 message thread spans 2 pages: 35