我希望有人可以帮助我。我根本不习惯Perl,但我有编程经验,我正在修建一个有多个联系表单的客户网站。一个联系表单正在工作,但如果我尝试更改.pl文件它不起作用,即使我只是重命名它。示例文件contact.pl正在运行,但是如果我重命名为contact1.pl并从联系表单中引用此文件,则会出现“500内部服务器错误。”
我知道由于我缺乏Perl的经验,这可能很简单。
这是联系表格上的代码
<form id="contactForm" class="cmxform" method="post" action="http://www.mysite.com/cgi-bin/contact.pl" name="contactForm">
<div>
<label for="contact_name">Name</label><em>(required)</em><br />
<input id="contact_name" name="contact_name" size="30" class="required" minlength="2" value="" /> <input type="hidden" id="rules_contact_message" value="required" />
<input type="hidden" id="contact_name_required" value="Immetti un nome" /> <input type="hidden" id="contact_name_min_length" value="Your name must have at least two letters" />
</div>
<div>
<label for="contact_email">E-Mail</label><em>(required)</em><br />
<input id="contact_email" name="contact_email" size="30" class="required email" value="" />
<input type="hidden" id="messages_contact_email" value="Please enter a valid email address" />
</div>
<div>
<label for="contact_phone">Phone</label><em>(optional)</em><br />
<input id="contact_phone" name="contact_phone" size="14" class="phone" value="" maxlength="14" /> <label for="contact_ext">Extension</label> <input id="contact_ext" name="contact_ext" size="5" class="ext" value="" maxlength="5" />
</div>
<div>
<label for=country">Country</label><em>(required)</em><br />
<select id="country" name="country" class="Country">
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
</select>
<input type="hidden" id="rules_country_message" value="required" />
<input type="hidden" id="contact_country_required" value="Please select your country" />
</div>
<div>
<label for="contact_message">Enter your Message:</label><em>(required)</em><br />
<textarea id="contact_message" name="contact_message" cols="70" rows="7" class= "required"></textarea>
<input type="hidden" id="messages_contact_message" value="Please enter your message" />
</div>
<div>
<input name="submit" class="submit" type="submit" value="Submit" />
</div>
这是来自contact.pl的代码
#!/usr/bin/perl
$mail_prog = '/usr/lib/sendmail' ;
&GetFormInput;
$contact_name = $field{'contact_name'} ;
$contact_email = $field{'contact_email'} ;
$contact_phone = $field{'contact_phone'} ;
$contact_ext = $field{'contact_ext'} ;
$country = $field{'country'} ;
$contact_message = $field{'contact_message'} ;
$message = "" ;
$found_err = "" ;
$recip = "info\@mysite.com" ;
open (MAIL, "|$mail_prog -t");
print MAIL "To: $recip\n";
print MAIL "Reply-to: enquiry\@mysite.com\n";
print MAIL "From: enquiry\@mysite.com\n";
print MAIL "Subject: Contact form submission - English\n";
print MAIL "\n\n";
print MAIL "Please find the information submitted from the contact form:\n" ;
print MAIL "\n" ;
print MAIL "Name: ".$contact_name."\n" ;
print MAIL "\n" ;
print MAIL "Email: ".$contact_email."\n" ;
print MAIL "\n" ;
print MAIL "Phone: ".$contact_phone."\n" ;
print MAIL "\n" ;
print MAIL "Phone Extension: ".$contact_ext."\n" ;
print MAIL "\n" ;
print MAIL "Country: ".$country."\n" ;
print MAIL "\n" ;
print MAIL "Message: ".$contact_message."\n" ;
print MAIL "\n\n";
close (MAIL);
print "Location: http://www.mysite.com/thank-you.html\nURI:http://www.mysite.com/thank-you.html\n\n" ;
sub PrintError {
print "Content-type: text/html\n\n";
print $message ;
exit 0 ;
return 1 ;
}
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){
($contact_name,$val)=split (/=/,$fval[$i],2);
$val=~tr/+/ /;
$val=~ s/%(..)/pack("c",hex($1))/ge;
$contact_name=~tr/+/ /;
$contact_name=~ s/%(..)/pack("c",hex($1))/ge;
if (!defined($field{$contact_name})) {
$field{$contact_name}=$val;
}
else {
$field{$contact_name} .= ",$val";
#if you want multi-selects to goto into an array change to:
#$field{$contact_name} .= "\0$val";
}
}
}
return 1;
}