当我尝试在我的CGI脚本中使用Email :: Valid时,我注意到我得到内部服务器错误500 。我是这里的新手,所以我无法理解问题所在。我尝试使用Email :: Valid来编写一个简单的表单验证器,以验证电子邮件地址,但是当我尝试放置行时
use Email::Valid;
它给了我错误。这是我的完整代码:
#!C:\xampp\perl\bin\perl.exe
use Email::Valid;
use CGI;
my $query = new CGI;
print $query->header ( );
my $nome = $query->param("Nome");
my $email_address = $query->param("Email");
my $website = $query->param("Website");
my $comments = $query->param("Messaggio");
$nome = filter ( $nome );
unless( Email::Valid->address($email_address) ) {
$email_address = "Invalid email address";
}
$website = filter ( $website );
$comments = filter ( $comments );
print "Nome: $nome<br>";
print "Email: $email_address<br>";
print "Sito: $website<br>";
print "$comments<br>";
print <<END_HTML;
<html>
<head></head>
<body>Thanks for filling in our form!</body>
</html>
END_HTML
sub filter
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
$field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}
使用没有Email :: Valid的代码时,它运行正常!
#!C:\xampp\perl\bin\perl.exe
use CGI;
my $query = new CGI;
print $query->header ( );
my $nome = $query->param("Nome");
my $email_address = $query->param("Email");
my $website = $query->param("Website");
my $comments = $query->param("Messaggio");
$nome = filter ( $nome );
$email_address = filter ( $email_address );
$website = filter ( $website );
$comments = filter ( $comments );
print "Nome: $nome<br>";
print "Email: $email_address<br>";
print "Sito: $website<br>";
print "$comments<br>";
print <<END_HTML;
<html>
<head></head>
<body>Thanks for filling in our form!</body>
</html>
END_HTML
sub filter
{
my $field = shift;
$field =~ s/From://gi;
$field =~ s/To://gi;
$field =~ s/BCC://gi;
$field =~ s/CC://gi;
$field =~ s/Subject://gi;
$field =~ s/Content-Type://gi;
$field =~ s/[\0\n\r\|\!\/\<\>\^\$\%\*\&]+/ /g;
return $field;
}
答案 0 :(得分:0)
经过一番搜索,我发现通过XAMPP运行的Perl服务器没有成功安装模块。我决定转换到顺利运行的草莓!所以问题是XAMPP和模块安装。
感谢所有人的建议和帮助