Saturday, 28 September 2013

perl contact form error 500

perl contact form error 500

I'm hoping someone can help me. I'm not used to perl at all but I have
programming experience and I am working on fixing a clients website that
has multiple contact forms. One contact form is working but if I try to
change the .pl file it doesn't work, even if I just rename it. example
file contact.pl is working but if i rename to contact1.pl and reference
this file from the contact form i get a '500 internal server error.
I know this is probably something simple due to my lack of experience with
perl.
here is the code on the contact form
<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>
and here is the code from 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;
}

No comments:

Post a Comment