Jump to content

CGI mail forms


BigAl75

Recommended Posts

I'm homeright now, but I'm having problems at work with a cgi mail form. It'sa basic form that allows people to sign up for our newsletter. They enter their name, company name, email address and website if they have one. Does anyone have any recommendations as to what I should use instead of using cgi? The cgi forms are nice, but if you have one little bug, it can cost you hours of searching for it.I'll post the code tomorrow at work to see if anyone here can spot what I did wrong.

Link to comment
Share on other sites

Yeah, it's done in perl. Here's the cgi script:

#!/usr/bin/perlprint "Content-type: text/html\n\n";# Set the variables$mailprog = '/usr/sbin/sendmail';$recipient = 'MYEMAIL';$date_command = "/usr/bin/date";$date = `$date_command`;# Get the inputread(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});# Split the name-value pairs@pairs = split(/&/, $buffer);foreach $pair (@pairs) {	($name, $value) = split(/=/, $pair);		# Un-webify plus signs and %-encoding	$value =~ tr/+/ /;	$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;	$value =~ s/<!--(.|\n)*-->//g;	if ($allow_html != 1) {		$value =~ s/<([^>]|\n)*>//g;	}	$FORM{$name} = $value;}####################### send the mail ###############################open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";print MAIL <<STOP;To: $FORM{"to"}From: $FORM{"feedback_provider_email"}Subject: $FORM{"formname"}Submitted: $date===================================================APP FEEDBACK FORM===================================================FEEDBACK PROVIDER CONTACT INFORMATIONForm of Address:  $FORM{"newsletter_address_title"}Name:  $FORM{"newsletter_firstname"}  $FORM{"newsletter_middlename"}  $FORM{"newsletter_lastname"}Company Name:  $FORM{"newsletter_company"}Company Email:  $FORM{"newsletter_email"}Company Website: $FORM{"newsletter_website"}====================================================STOPclose MAIL;################## return html ##########################print "Content-type:text/html\n\n";#Thank the user. Anything else you print here will appear on the htmlpage.print '<title>APP Feedback Form</title>';print '<BODY BGCOLOR=#FFFFFF>';print '<BIG>Form successfully sent.</p>';print 'We will respond promptly.</BIG><p>';print '<A HREF="http://www.pmiapp.com/news/index.html">Back to the news page</A>'

And here's the html:

<form action="path-to-script" method="POST">						<div>							<p>Please complete this form to sign-up for the PMI newsletter. When finished, press the submit button at the end of the page.</p>							<p>You can preview the newsletter <a href="newsletter_April_2007/preview_April_newsletter.pdf" target="_blank">here</a>.</p>							<p><strong>Registration Form:</strong></p>						</div>						<div style="padding: 10px;">							<!-- Start Name Forms -->								<input type="hidden" name="to" value="MYEMAIL" />								<input type="hidden" name="formname" value="PMI Newsletter Sign-Up" />									<div style="padding: 10px;">										<strong>Title:</strong> <select name="newsletter_address_title" size="1">																  <option selected="selected">--</option>																  <option>Mr.</option>																  <option>Ms.</option>																  <option>Dr.</option>																</select>									</div>									<div style="padding: 10px;"> 										<strong>First Name:</strong> <input type="text" size="17" maxlength="100" name="newsletter_firstname" />									</div>									<div style="padding: 10px;">										<strong>MI:</strong> <input type="text" size="4" maxlength="1" name="newsletter_middlename" />									</div>									<div style="padding: 10px;">										<strong>Last Name:</strong> <input type="text" size="17" maxlength="100" name="newsletter_lastname" />									</div>							<!-- End Name Forms -->						</div>						<div style="padding: 10px;">							<!-- Start Contact Information Forms -->									<div style="padding: 10px;">										<strong>Company Name:</strong> <input type="text" size="45" maxlength="150" name="newsletter_company" />									</div>									<div style="padding: 10px;">										<strong>Email:</strong> <input type="text" size="40" maxlength="100" name="newsletter_email" />									</div>									<div style="padding: 10px;">										<strong>Website:</strong> <input name="newsletter_website" type="text" value="http://www." size="40" maxlength="100" />									</div>							<!-- Begin Submit/Reset buttons -->								<input type="submit" name="button" value="Submit" />   <input type="reset" name="reset" value="Reset" />									<p>Please only press the submit button once, and only after you are sure all of your information is correct.  It may take a few seconds to submit your data.</p>							<!-- End Submit/Reset buttons -->						</div>					</form>

Link to comment
Share on other sites

Can't you use PHP? Then I would be able to help you, but hey! I will try out that script...I can use CGI and Perl on my site but I have never tried it before. Don't really understand it hehe

Link to comment
Share on other sites

I don't know php that well at all, and know even less about cgi. I was just using what they have available.To be honest with you, if I knew php better, I'd redo the entire site in php. The php include() would be a wonderful addition to this site instead of having the exact same right and left columns hard-coded into the html on every page.

Link to comment
Share on other sites

Yeah, that's fine. I just thought there might be someone here who would know a thing or two about it and who might be able to see what I did wrong by taking a peek at the code.Thanks for the link.

Link to comment
Share on other sites

OK, I still haven't gotten this working. Does anyone have any suggestions as to what I could use as an alternative? I don't have PHP installed on the server, and I can't install it either. We're working under strict conditions, and have limited resources. Even if I could find some free script I could add to the page that would just send the person's email address to my company email would be better than fighting with this any longer.

Link to comment
Share on other sites

OK, I still haven't gotten this working.
Do you have any idea where the error is occurring? Does anything at all happen when you submit the form? Maybe if you describe the problem you are having in greater detail, one of us might be able to hack our way through it. If you can't install PHP, and SSI is disabled, you probably aren't going to be able to install any server-side solution other than CGI. CGI/Perl has been around for a great many years, I'm sure if we aren't able to help you here, you'll be able to find some free scripts using Google: http://www.google.com/search?q=cgi+mail+script
Link to comment
Share on other sites

When I first started here, I was asked to create an online form so that people from other companies who wanted to register for our short course could do so online. I messed around with a couple of cgi/perl scripts that were all ready on the site and working, and was able to create one for the short course registration. After about a month, I was given the task of creating a company newsletter, and I suggested having a way for visitors to sign-up for it on the website. I did the same with this form as I did for the course registration - took one that was all ready working, and edited it to fit my needs. Now, every time you fill out the form and hit the subit button, all I get is 500 Internal Server errors. We've accessed the error log, but can't find any error. No emails are going through (I've even tested the origina one I made - same thing), and all we get are the 500 IS errors. I'm at a loss. We have another short course coming up this fall, and I want the online registration form to at least work.

Link to comment
Share on other sites

There are numerous potential causes of this error, the most common being: * The correct permissions have not been set. * The file was uploaded in binary mode instead of ASII. * There is an error in the script.Try running the script on command line (with -wc) to catch any syntax errors

perl -wc scriptname.pl

Has there been any server changes since you noticed your original form was working?

Link to comment
Share on other sites

OK, thanks for your help and your patience. I finally found out what I was doing wrong:The file was uploaded in binary mode instead of ASCII.The ftp program I'm using is different than any of the others I've used. After playing around with it, and getting help from the guy who suggested it to me, I finally found where to change it from Binary to ASCII.Hard to believe that was the problem, but it's working now.Thanks again.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...