Didnt know where else to post this type of question .. so if this is the wrong area please forgive me. It has been quite a while since i've posted here.
I am working on creating a simple CGI/Perl script to e-mail a form. Nothing fancy.
Below is the code I am working with. Basically I can post to the script and it runs, but I never receive an e-mail/ never get an error message. If you all can provide me with posssible problems I would be much ablidged. I usually don't deal with perl at all, but in this case I don't have the choice.
#!/usr/bin/perl
use CGI;
my $sendmail = "/usr/sbin/sendmail";
my $emailConfPath = "/export/home/fac/mis16/public_html/email.conf";
# Parse any submitted form fields and return an object we can use
# to retrieve them
my $query = new CGI;
my $name = &clean($query->param('name'));
my $email = &clean($query->param('email'));
my $recipient = &clean($query->param('recipient'));
my $content = &clean($query->param('content'));
my $subject = &clean($query->param('subject'));
#Note: subject is not mandatory, but you can easily change that
if (($name eq "") || ($email eq "") || ($content eq "") || ($recipient eq ""))
{
&error("Email Rejected",
"Please fill out all fields provided. Back up to the " .
"previous page to try again.");
}
if (!open(IN, "$emailConfPath")) {
&error("Configuration Error",
"The file $emailConfPath does not exist or cannot be " .
"opened. Please read the documentation before installing " .
"email.cgi.");
}
my $returnpage;
my $ok = 0;
while (1) {
my $recipientc = <IN>;
$recipientc =~ s/\s+$//;
if ($recipientc eq "") {
last;
}
my $returnpagec = <IN>;
$returnpagec =~ s/\s+$//;
if ($returnpagec eq "") {
last;
}
if ($recipientc eq $recipient) {
$ok = 1;
$returnpage = $returnpagec;
last;
}
}
close(IN);
if (!$ok) {
&error("Email Rejected",
"The requested destination address is not one of " .
"the permitted email recipients. Please read the " .
"documentation before installing email.cgi.");
}
# Open a pipe to the sendmail program
open(OUT, "|$sendmail -t");
# Use the highly convenient <<EOM notation to include the message
# in this script more or less as it will actually appear
print OUT <<EOM
To: $recipient
Subject: $subject
Reply-To: $email
Supposedly-From: $name
[This message was sent through a www-email gateway.]
$content
EOM
;
close(OUT);
# Now redirect to the appropriate "landing" page for this recipient.
print $query->redirect($returnpage);
exit 0;
sub clean
{
# Clean up any leading and trailing whitespace
# using regular expressions.
my $s = shift @_;
$s =~ s/^\s+//;
$s =~ s/\s+$//;
return $s;
}
sub error
{
# Output a valid HTML page as an error message
my($title, $content) = @_;
print $query->header;
print <<EOM
<html>
<head>
<title>$title</title>
</head>
<body>
<h1 align="center">$title</h1>
<p>
$content
</p>
EOM
;
exit 0;
}