Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm having trouble getting my chi script to run!

Status
Not open for further replies.

shawnmcn

Programmer
Jan 13, 2003
2
CA
Hi,

I'm running my perl script on a apache unix server, with windows 2000 o/s, I believe the perl script works, I'm calling the form form html/form/supportform.html, the cgi-bin is at the same level as html folder is. I can't get it to run.

Could you please look at my script.

Thanks

Shawn

#!/usr/bin/perl
$mail_prog = '/usr/sbin/sendmail -t';

# recieving info e-mail address
$contact_mail = "shawnm\@komnetworks.com";
@all;
$subject = "Online Support Help Form";

sub GetFormInput {
(*fval) = @_ if @_ ;
local ($buf);
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN,$buf,$ENV{'CONTENT_LENGTH'});
} else {
$buf=$ENV{'QUERY_STRING'};
}
if ($buf eq "") {
return 0 ;
} else {
@fval=split(/&/,$buf);
foreach $i (0 .. $#fval) {
($name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$name=~tr/+/ /;
$name=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($field{$name})) {
$field{$name}=$val;
} else {
$field{$name} .= ",$val";
}
}
}
return 1;
}

sub AssignValues {


if ($field{'NEEDS_TECHNICAL_SUPPORT_HELP'} eq "")
{
$field{'NEEDS_TECHNICAL_SUPPORT_HELP'} = "YES"
}
else
{
$field{'NEEDS_TECHNICAL_SUPPORT_HELP'} = "NO"
}

@ProductLicense = ("Product License ", $field{'ProductLicense'});
@all = (@all, @ProductLicense);

@Organization = ("Organization ", $field{'Organization'});
@all = (@all, @Organization);

@ContactName = ("Contact Name ", $field{'ContactName'});
@all = (@all, @ContactName);

@Phone = ("Phone ", $field{'Phone'});
@all = (@all, @Phone);

@EmailAddress = ("Email Address ", $field{'EmailAddress'});
@all = (@all, @AddressEmail);

@RequestType = ("Request Type ", $field{'RequestType'});
@all = (@all, @RequestType);

@ProductName = ("Product Name ", $field{'ProductName'});
@all = (@all, @ProductName);

@Subject = ("Subject ", $field{'Subject'});
@all = (@all, @Subject);

@Severity = ("Severity ", $field{'Severity'});
@all = (@all, @Severity);

@DescriptionofRequest = ("Description of Request ", $field{'DescriptionofRequest'});
@all = (@all, @DescriptionofRequest);

@UploadaFile = ("Upload File ", $field{'UploadaFile'});
@all = (@all, @UploadaFile);

@AdditionalNotes = ("Additional Notes ", $field{'AdditionalNotes'});
@all = (@all, @AdditionalNotes);


sub ThankYou {

print "Content-type: text/html\n\n";
$html_template = "/ open(TEMPLATE,$html_template);
while(<TEMPLATE>) {
$Line = $_;
foreach $name (keys %field) {
$Line =~ s/{$name}/$field{$name}/g;
}
print $Line;

}
close(TEMPLATE);
}


sub SendMailTo
{
open(MAIL,&quot;|$mail_prog&quot;);
print MAIL &quot;To: $contact_mail\n&quot;;
print MAIL &quot;From: $field{'Email'}\n&quot;;
print MAIL &quot;Subject: $subject\n&quot;;

print MAIL &quot;This user was interested in ON-Line Support Help\n\n&quot;;


$counter = 0;
foreach $val (@all)
{
if ($counter == 2)
{
$counter = 0;
print MAIL &quot;_________________________________________________\n&quot;;

}

if ($val eq &quot;&quot;) {
print MAIL &quot;Not Submitted \n&quot;;

}
else {
print MAIL &quot;$val \n&quot;;
}
$counter++;
}

print MAIL &quot;\n\n&quot;;
close (MAIL);
}

sub SendMailFrom
{
open(MAIL,&quot;|$mail_prog&quot;);
print MAIL &quot;To: $field{'Email'}\n&quot;;
print MAIL &quot;From: $contact_mail\n&quot;;
print MAIL &quot;Subject: $subject\n&quot;;

$mail_template = &quot;/ print MAIL &quot;Dear $field{'FirstName'}, \n&quot;;
open(TEMPLATE,$mail_template);
while(<TEMPLATE>) {
$Le = $_;
print MAIL $Le;
}
print MAIL &quot;\n\n&quot;;
close (MAIL);
}

}

&GetFormInput;
&AssignValues;
&ThankYou;
&SendMailTo;
&SendMailFrom;
 
The syntax of the code you posted looks ok. However, it appears to have been written to run on a Unix or Linux OS.

-quote-
...on a apache unix server, with windows 2000 o/s
-/quote


Unix is a flavor of operating system. You can not be running apache on a unix server and a win2k server at the same time. I assume the above means you are running an apache web server on a win2k box.

If that is the case, there are a few problems with the code you are trying to run.

When running apache on a win box, apache uses the top line in the Perl/CGI code to identify the location of the perl interpreter on your box. Since you are on a win box, the perl path '#!/usr/bin/perl' probably not correct. Windows paths generally start with a drive letter designation and don't usually look/smell like a unix/linux style path. #!/usr/bin/perl looks and smells like a *nix path.

Also, the code is trying to use the 'sendmail' utility to send the emails. To my knowledge, there is no 'sendmail' program for M$ boxes. If you are going to use this code, you'll need to find a suitable replacement for sendmail. I have never used it, but I hear people have successfully used a tool called 'blat.exe' to replace sendmail. You'd have to get 'blat.exe' (see google) and modify the code to use blat. Or, you could also use the Mail::Sender module. I'd lean toward using Mail::Sender.

There are a few faqs under the faqs tab at the top of this page about the basics of running CGIs. Please take a look at the faqs and come back with any questions.

Good Luck. 'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Also, you should &quot;use strict&quot; and declare all variables with &quot;my&quot;. Then report back with specific error messages which are confounding you.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
I have a unix box linux/unix apache server, I am using windows 2000 for my o/s. From my form I have it directed to action&quot;/cgi-bin/supportform.cgi.

When I run it it tells me line 8 and line 12 something with the variable.
This code is to suppose to run on apache unix server. I seem to always get a server error 500. Is there something I can do to might my script to work.

Shawn
 
I have a unix box linux/unix apache server, I am using windows 2000 for my o/s.

I'm sorry, but this makes no sense at all. Unix is a class of operating system, linux is a specific operating system, and Win2k is a specific operating system. You can only be running your web server on one of these at a time unless you are somehow doing load-balancing across several machines. I assume that you are not, as that would require much more expertise than running a simple script. So please figure out which operating system you are actually using. If you have a &quot;START&quot; button in the corner of your screen, it is Win2k. If you type &quot;gcc --version&quot; at the command line and it returns version information instead of an error, then you are running linux.

Are you trying to say that your web server is Apache running on linux and your workstation is Win2k? That's the only way I can make sense of what you are saying. If that's the case, then you must be FTP'ing your script from your Win2k workstation to your linux server. Make sure that you are using ASCII mode.

Please read faq452-3023 and apply the solutions suggested. If you are still having problems, come back here and post full error strings.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top