Can anyone help me understand why this code runs from the command line but not from a cgi script? When I type:
perl myscript.pl
at the Linux command line, it runs perfectly. But when I embed the code in a cgi script and call it from a web form it does not run. I don't get a syntax error, I just do not get the mail. I don't think it's an
environmental problem. My script sets all the required environment variables and paths, so the cgi knows where sendmail is, etc. Any ideas? Thanks.
Assume $cleartext1 and $recipient are set. Also assume that cgi has appropriate #!/usr/bin/perl in the header, etc. (ie, all the simple stuff is covered).
# Load Open2 module for bi-directional I/O
use IPC::Open2;
&cat_order;
&send_order;
sub cat_order {
# Set up the cat command
$catcmd = "cat -u";
# Open the cat program for bidirectional I/O
$pid = open2(\*READER, \*WRITER, $catcmd) || die "Can't open cat: $!\n";
# Send text to cat
print WRITER $cleartext1;
# Send the data
close(WRITER);
# Get the data from cat
@cattext = <READER>;
close(READER);
}
sub send_order {
# Open The Mail Program
open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog: $!\n";
# Standard headers
print MAIL "From: Administrator \<admin\@mysite.com\>\n";
print MAIL "To: $recipient\n";
print MAIL "Subject: In-Line ClearText Test\n\n";
print MAIL @cattext;
close (MAIL);
}