View Full Version : Forms, CGI, perl...Arrrghh
dan_bradshaw
06-15-2004, 06:32 AM
Hi all,
Have set up a feedback form in my website http://www.cubid.co.uk/contact.htm
though I am having trouble writing or getting a script to send it my server and then back to me.
I understand that the best method is to use CGI scripting (have located the bin etc on my server) though am having trouble setting one up for my forms.
Can anyone help? or offer some scripting for my page? http://www.cubid.co.uk/contact.htm
Cheers
Dan
M0rtym0use
06-15-2004, 07:23 AM
dan_bradshaw,
it appears that the file you are referencing does not exist
try this...
http://www.cubid.co.uk/cgi-bin/mylog.cgi
as the path to the cgi file
remember the root of the website is the www not root of the file system
MM
dan_bradshaw
06-15-2004, 07:55 AM
Thanks for this, will have a go at that. Do you mean the link from my submit button?
Thanks for your help
dan_bradshaw
06-15-2004, 09:42 AM
Have tried this though am now getting the internal message error...do you think it maybe my script that is causing the problem?
Are you able to view the script for me?
Thanks
Dan
M0rtym0use
06-15-2004, 11:30 AM
dan_bradshaw,
Sorry i no v.little about cgi itself but you may want to check that there are execute permissions on that folder etc as this could be causing this.
MM
dan_bradshaw
06-16-2004, 08:34 AM
Hi all,
I am having real trouble with my forms and script to process them.
All that keeps coming up is
500 Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, info@cubid.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.
Is anyone able to help me?
I can them the script and other details if necessary
Cheers
Dan
jdiben
06-16-2004, 09:38 AM
Try removing the second "form" from the following line
<form action="http://www.cubid.co.uk/cgi-bin/formmail.pl" form method=post name=form1>
Joe
dan_bradshaw
06-16-2004, 09:47 AM
I have replaced the form with a much simpler form and made sure that I have not got any extra formsin now. The dam thing still doesn't work...grrr
I don't think it could be related, but the e-mail address I have got the script forwarding to is one which has a auto responder, could this be affecting it?
I cannot give a precise solution, but it could be a problem related to permissions of the perl files.
Otherwise it could be that the path to perl is not correct.
Your sever should have a good help desk. Someone there should be able to point you in the right direction.
I cannot give a precise solution, but it could be a problem related to permissions of the perl files.
Otherwise it could be that the path to perl is not correct.
G[dot]com
06-16-2004, 04:48 PM
Dan, Hi!
As Zelo mention this is something that the people of the hosting in which you have your site MUST help you with.
Moreover, before you do anything on your own and waste time and stress yourself out, it is convenient that you contact the help desk and ask as a 2 year-old boy:
"Hi I have to add some forms to in my site. Which aplications do you use to process the scripts? And do you have templates to send to me so I customize them with my needs?"
They have to help you, and they will give you excactly the information you need for your site. No one will know better than them.
Hope I am helping you with this, kiss,
Gi
chowell
06-16-2004, 04:50 PM
The error you're receiving is generally caused by one of the following...
1) The file permissions of your formmail.pl file are not correct. They should be set to "755" in order to properly run the script.
2) The file was not uploaded using Auto-ASCII or ASCII. If you upload the file in "binary" mode, it will not work properly.
3) The first line in the formmail.pl file is not the correct path to perl. (ie: #!/usr/bin/perl). The default path is not always right. You should check with your host for the correct path.
I'm pretty confident that this information will help you get the form working properly.
epern
06-16-2004, 06:41 PM
Hi,
I had the same problem . I re-checked the "755" rule, ascii only upload, correct file location (BTW, After I started using CuteFTP , the EXACT location of server files became more clear. Dreamweaver befuddled things a bit)
I was still getting errors...
Anyhoo, I edited the actual mailform.pl file and deleted the "@referer" section. About 15 lines of code.
This did the trick for me.
Now... I would love it if someone could explain the finer points of ordering the data!! I have 15 "inputs" in a logical order on my form(name, address, coutry, phone, etc...), when the data is parsed and emailed, it seems to be in a random order in the resulting email.
Thanks and good luck!
kenmcc
06-16-2004, 06:46 PM
I agree with chowell...
Personally I ditched this method a few years ago, mainly because of the security holes associated with cgi mail scripts like formmail, also because you can't do stuff like send html mail.
Have you tried using the php mail function? Its far more flexible... here's an example script
<?php
// Ken McCormack / P21
$recipient = "recipient@domain.com.au";
// do not pass email recipient from form!!
$recipient_name = "Fred Smith";
if ($submit) {
// if form has been submitted, send mail
$name = $_POST['firstName'] ." " . $_POST['lastName'];
$text = $_POST['message'] . date("jS F Y G:i:s");
$redirect = $_POST['redirect'];
$email = $_POST['Email']; // sender's email
$head = "MIME-Version: 1.0\r\n";
$head .= "Content-type: text/plain\r\n";
// or for html formatting
// $head .= "Content-type: text/html; charset=iso-8859-1\r\n"; // for html mail
$head .= "From: " . $name . " <" . $email . ">\r\n";
$head .= "To: " . $recipient_name . " <" . $recipient . ">\r\n";
$head .= "Reply-To: ". $name . " <". $email .">\r\n";
$head .= "X-Priority: 2\r\n";
$head .= "X-MSMail-Priority: Normal\r\n";
$head .= "X-Mailer: PHP";
$subject = "Site Name Website Enquiry - " . $fullname;
mail($recipient, $subject, $text, $head);
// redirect to next page
header('Location: ' . $redirect); /* Redirect browser */
exit;
} // end if
?>
That's all there is to it! If you're not conversant with Perl, PHP mail is a much more user friendly means to control mail from web forms.
paulhiles
06-16-2004, 06:58 PM
If it's just HTML formatted emails you're after, PHP is certainly not the only alternative.. most mailer scripts have some means of formatting the email that is sent.
I've used a variety of Perl, CGI and ASP scripts that have ALL offered the possibility of HTML emails... IMO the choice of scripting language is immaterial... as has been suggested earlier Dan, check with your hosting support first.. they may have ready-made solutions for you. If that doesn't help, feel free to send me the script and I'll help in any way I can.
Paul
kenmcc
06-16-2004, 09:59 PM
I give up, make a suggestion and you get a response like that. What a waste of time. Time to unsubscribe.
G[dot]com
06-16-2004, 10:21 PM
kenmcc,
You are *very* welcome TO leaving.
Actually Iīd like to see no more people here being agressive or critizizing otherīs posts and help.
So, please, Kenmcc, unsubscribe the sooner.
And if you know some one else that thinks like you about this forum, it would be great if they join you.
:o)
Gisela
HardCoded
06-17-2004, 12:58 AM
Geez, quit helping people Paul.
ken, the real point is that the poor guy can't run CGI scripts. That's not useful. He should check with his host and get the paths straightened out.
And while I agree that formmail.pl is notorious for being spam bait, it is certainly possible to write a secure perl script. And an insecure PHP script.
You will also get this error if you do not put an escape character in the email address in the scritp.
you\@you.com
dan_bradshaw
06-17-2004, 04:48 AM
Hi,
Thanks for all your comments and suggestions, I will check them all out this morning... I have been on to the hosts who seem to be sorting things out, or at least looking into it.
Not sure what kenmcc was on about...
PHP does sound more user friendly, though I will also go back and check the code.
Have many other people used the formmail from scriptarchives.com? It seems pretty straight forward, only having to change a couple lines of code...however things are never as easy as they seem.
Thanks
Hope you are all routing for England lads today.
Dan
Cubid Imagery...Innovative Solutions and Creative Web Designs...when it works
www.cubid.co.uk
info@cubid.co.uk
G[dot]com
06-17-2004, 05:18 AM
Hope your hosts help you to get a definite solution, Dan.
I bet they will be able to. They are used to deal with these scriptīs *inconveniences*
And thank you for your thanks :o)
Kiss
Gi
BTW eventhough I am used to ASP because of my hosting services which run under Windows NT platforms (ASP friendly), I found that PHP is really simple.
Seems that the creators of PHP have clearer minds and more common sense than other language programmers :oP
paulhiles
06-17-2004, 05:38 AM
I give up, make a suggestion and you get a response like that. What a waste of time. Time to unsubscribe.
What can I say? My reply was contributing to the general discussion, there was no intention to demean your suggestion Ken. As Gisela says, PHP can offer very neat and user-friendly code, I have no doubt of that fact.
Dan's problem is mostly concerned with his CGI/Perl script, and I was offering to help if he got no joy from his hosting support.
Hope you are all routing for England lads today. Most certainly will be! 17:00 GMT kickoff.. come on you England!! :o)
Good luck with your script Dan, post back if you have any further problems.
dan_bradshaw
06-17-2004, 07:16 AM
Cheers again and thanks g[dot]com for your thanks and the little kiss. ;-D
dan_bradshaw
06-17-2004, 07:27 AM
<?php
// Is this the heading?
$recipient = "info@cubid.co.uk";
// do not pass email recipient from form!!
$recipient_name = "Cubid Imagery";
if ($submit) {
// if form has been submitted, send mail
$name = $_POST['firstName'] ." " . $_POST['lastName'];
$text = $_POST['message'] . date("jS F Y G:i:s");
$redirect = $_POST['redirect'];
$email = $_POST['Email']; // sender's email
$head = "MIME-Version: 1.0\r\n";
$head .= "Content-type: text/plain\r\n";
// or for html formatting
// $head .= "Content-type: text/html; charset=iso-8859-1\r\n"; // for html mail
$head .= "From: " . $name . " <" . $email . ">\r\n";
$head .= "To: " . $recipient_name . " <" . $recipient . ">\r\n";
$head .= "Reply-To: ". $name . " <". $email .">\r\n";
$head .= "X-Priority: 2\r\n";
$head .= "X-MSMail-Priority: Normal\r\n";
$head .= "X-Mailer: PHP";
$subject = "Site Name Website Enquiry - " . $fullname;
mail($recipient, $subject, $text, $head);
// redirect to next page do I need to put a redirect url in here or do I specifiy that in my form?
header('Location: ' . $redirect); /* Redirect browser */
exit;
} // end if
?>
Would I need to check with my server where to place PHP scripts or can they reside in the main files?
This does look simpler
Thanks
Dan
Hi Dan,
I've sent you some info. Hope it helps. Chowell is right on, though. The "big three" -- the ones most often missed -- are path to Perl, uploading in ASCII and setting permissions.
Would I need to check with my server where to place PHP scripts or can they reside in the main files?
You really don't want to try that. Keep them in the one, central location... cgi-bin.
By the way, an important note, here. It takes a lot of courage to "expose" yourself by showing that you don't know something which some people consider so basic... as if we are supposed to be "born" with such knowledge. Bravo on asking!!!
Good luck with it.
Hal
Hi epern,
Now... I would love it if someone could explain the finer points of ordering the data!! I have 15 "inputs" in a logical order on my form(name, address, coutry, phone, etc...), when the data is parsed and emailed, it seems to be in a random order in the resulting email.
I was just reading through the thread, again, and caught this. For me the answer was easy (after only a thousand or so tries).
After the <form method= stuff and the other hidden material -- enforced fields, redirect, etc. -- simply lay out the elements in the logical order in which you would like to see them. Name and email address field names will be governed by your system. For the rest, though, I give the fields names which begin with numbers...
Company <input type="text" size="30" name="03company">
Street <input type="text" size="30" name="04address">
City, ST ZIP <input type="text" size="30" name="05city">
Country <input type="text" size="30" name="06country">
And so on. Now, either your server's form script has a sorting option, or it happens automatically. Whatever. Set it if you can get it. Then, by starting the field name with a number, the email you receive will always have the entries in the right order.
Hal
G[dot]com
06-18-2004, 09:33 AM
Great post, Hal. Indeed. Thank you for you help.
:o)
HardCoded
06-19-2004, 01:48 AM
You really don't want to try that. Keep them in the one, central location... cgi-bin.
Well, I have to disagree with that. PHP and PHP scripts are more secure when run as module. And faster too.
ozchris
06-23-2004, 12:51 AM
I'm trying to learn PHP and forms, too.
Experimenting at http://christmas.best-australian.com/formtester2.htm
I only have 2 fields in the form: name and email.
In the PHP I am sending an email to trigger my autoresponder.
When I check the contents of the autoresponder, it exports email,registration date,firstname,lastname etc.
So in the PHP I assigned name to firstname. Printed it to prove the assign worked. But by the time it gets to the autoresponder, the email address is plugged into the firstname field.
And this was only trying to send one variable to the autoresponder cos I didn't have the guts to try more. What have I stuffed up?
$firstname = "$name";
print "
Firstname is $firstname";
$recipient = "oztesting@kioskcities.com";
$subject = "Subscribe";
$message = "$firstname";
$extra = "From: $email\r\nReply-To: $recipient\r\n";
mail ($recipient, $subject, $message, $extra);
Interesting also, my CSS won't centre the thank you page the way it does on formtester2.htm.
ta Chris
computergenius
06-28-2004, 04:21 PM
I notice that if you leave some fields out, then formmail.pl *is* found!
*IF* you ever get it working <G>, note that you have your email address in the source of the contact form, so spam harvester can find it. Also, you use the variable name "realname" for the visitors name - if they leave it out, they get the message
"The following fields were left blank in your submission form:
realname "
which probably means nothing to a normal human!
Also, I thought that there was some security issue with formmail.pl - has that been fixed now?
I would have used PHP, but that is probably because I know it best.
Good luck
davebarnes
06-28-2004, 04:57 PM
paulhiles wrote: " IMO the choice of scripting language is immaterial."
I would partially disagree.
1. I have 35+ years of programming experience.
2. In 1998 when Perl scripts were the only choice (or so I thought) for backend processing, I spent some time to modify a simple Perl script to process a Request Info form and have it send email. What I found was that most (not all) Perl script writers seem to pride themselves on writing clever cryptic code.
3. Then I found H20 from Aestiva (http://h2o.aestiva.com). The entry-level product is FREE and the code is very BASIC-like. Easy to use and very powerful. I have used it on over 20 websites and continue to use it.
4. Recently, I spent some time learning PHP and used it on 5 websites. I find that PHP is much easier to use than Perl, it has more support (www.phphelp.com among others). It is more difficult to use than H2O. Sending emails is MUCH more complicated. To help me learn PHP, I wrote a tutorial (www.marketingtactics.com/requestinfoprimer/).
All languages are not the same in terms of ease-of-use.
,dave
tviman
06-28-2004, 06:39 PM
Dan,
post your perl code here. it's going to be a simple fix - there can't be that much wrong with a form mailer.
TrafficProducer
06-28-2004, 06:51 PM
Make sure the top line is pointing to PERL on your server
For example, may be different on your server
#!/usr/bin/perl
Only upload as ASCII to correct file location, the correct directory usually, may be different on your server: -
cgi-bin
Extension of (CaSe Sensitive), filename usually .cgi
Set to executable permission (755)
Test with a simple piece of code first.
siterender1
06-28-2004, 07:52 PM
I am just adding to the group here, but if you can not get information from your hosting provider.........drop them!!! I hate to sound like that, but there is TOOO many hosting companies out there that can do you a lot better.. most provide mail scripts on there site for free use,,, so check others out.. you should not be going through all this jazz when you want ROCK and ROLL!!
Although I do like jazz, but.. well never mind
Now on the other hand if this is your own server, or if a buddy is providing you with use on there server, I would suggest that you get with someone that understands server security and what not. The reason is that if you get your script running right,, your happy, your client is happy, birds are chirping.. you get the picture.. then your script is "hi-jacked", then all heck break's loose. The server enviroment when using ANY cgi script, needs to be locked down correctly... that could be the problem also. Most host's have a "script directory" for clients using a method called "alias, Script Alias, etc".. meaning that if you want to use a script, the directory has to be a pre-defined one, and your "privaleges" need to be turned on.
Boy, this web thing can be fun and huh!!!
Peace
DrTandem1
06-29-2004, 12:17 AM
Yes, a good number of problems regarding CGI internal errors are incorrect settings of the permissions (chmod). Adding to the problem, if you make a scripting mistake, many servers will lock up the permissions and you will need to reset them again.
You need to go to the directory where the file resides and list the permissions. If you are good at UNIX, then this will not be a problem. Some FTP programs as well as web-based site managers allow for GUI access to the permissions. This is of great help for those not versed in UNIX.
tviman
06-29-2004, 10:23 AM
CGI internal errors (the 500 Internal server error) are neer caused by incorrect server settings. This error is 99.99% a scripting error. The other .01% falls under the part of the server doesn't support a feature that you're trying to use in the script.
Incorrect server settings or permissioins will will alwasy yeild an error stating as much. So, to help with Dan's original post, we need to see his script before we can begin to do any kind of diagnostics.
dan_bradshaw
06-29-2004, 11:07 AM
The script that I used originally was one from Matt Archive, however, after the changing the two bits I needed to, it still didn't work, urrrm. Well I pulled my hair out trying to get it to work.. think it turns out that the web hosts didn't have the bits in the right place, they re-wrote the code almost exactly as it was. God dam it.
Now I keep getting a 404 error, though I think thats because I accidentally deleted my response page ooops,
Good to see so many comments and replies, and also a show in WPW newslettter
Cheers
Dan
bizgen
06-30-2004, 03:49 AM
I was having a similar problem with Matts formmail.pl a week or so back. I kept getting 403 message suggesting it couldn't find the file.
I was confident the configuration was right so reported to my hosts. They tried it and it worked! So I tested it again, and got someone else to test it. It still didn't work. Went back to hosts. It worked for them again and they adopted the "your're an idiot that probably doesn't know squat" attitude. "Arrrrgggghhh" I said. (or words to that effect!)
I played around with permissions which made no difference. I played tennis with the help desk which still didn't help. Eventually I found the answer...
COOKIES & NORTON 2004!! formmail.pl collects them. If you (or your visitors) are running Norton Internet Security and Privacy Control is configured to block cookies, then NIS blocks the script, generating a file not found error in your browser.
Silly...but true!
I have now got a message on the site redirecting users who have this problem to an alternative mailto: form which I don't like.
Is anyone familiar enough with Matts formmail.pl to say which sections of the script can be removed to avoid this problem without effecting useability. I have no need to collect cookies as I get all the info I want from the form itself.
johreiki
07-05-2004, 04:10 AM
I've been having similar problems trying to process a form with a script. I've tried the famous FormMail (perl) script, and a security-enhanced version of it, both with no success. The support staff at my hosting company suggested a PHP script instead (from http://www.dtheatre.com/scripts/). I got it, and configured it as instructed (much simpler than the perl version)...and it's not working either.
I renamed the script mailingform.php, and configured the following lines of it:
================================================== ===// for ultimate security, use this instead of using the form
$recipient = "me@myaddress.com"; // youremail@domain.com
// bcc emails (separate multiples with commas (,))
$bcc = "";
// referers.. domains/ips that you will allow forms to
// reside on.
$referers = array ('alzheimerscaregivers.org','69.93.165.121');
================================================== ===
Whether I put my email address in the 'recipient' field of the script or in the form itself, I do not receive the email; and, when I press the 'Submit' button on the form, I'm sent to a default 'thank you' page, even though I have a redirect command in the form, for a custom 'thank you' page. Also, I'm sent to the default 'thank you' page even when I submit the form without filling out any of the fields (despite a tag in the form, which supposedly requires that all fields be filled out!)
In fact, just since I wrote this, I tried the form again....and pressing "Submit" (with the form either filled out or not filled out) is now sending me to http://www.medicaldomains.com/home.php !!!
The form is at: http://alzheimerscaregivers.org/FAQ.php
Thanks very much for any help! ---------
_||_
db
HardCoded
07-05-2004, 08:03 AM
You are posting to alzheimerscaregivers.com.
paulhiles
07-05-2004, 08:12 AM
You are posting to alzheimerscaregivers.com.
Well spotted HardCoded! The alzheimerscaregivers[dot]com address is then forwarding to medicaldomains[dot]com
johreiki
07-05-2004, 03:05 PM
You are posting to alzheimerscaregivers.com.
UGGHHH!!! I'm blushing now : ^ ).... Thanks so much for spotting that!
Now that I've changed it to .org....I still get the same result -- the default "Thank You" page, whether the form fields are filled out or not....
?????
_||_
db
BUT......LATER.....I found a different PHP script -- at http://www.tectite.com/ -- which is working for me.
YAYYYYYY!!!