> > Might be a faq, but why would open(FH,'|qmail-inject') fail with
> > fatal: read-error from within mod_perl?
> Use
> open MAIL, "| /var/qmail/bin/qmail-inject" or &die_html("test");
> print MAIL "[your mail]";
> close MAIL;
>
> I suppose you forgot the full path to qmail-inject ...
I use this, it's a bit more complete and paranoid:
# send mail from the system to someone
sub sendmail {
my ($from, $to, $subject, $message, $name) = @_;
local *MAIL;
# limit allowed characters in email addresses
$to =~ tr/-a-zA-Z0-9_+%$.,:!@=()[]//cd;
# safe pipes adapted from man perlipc
local $SIG{PIPE} = sub {};
my $pid = open (MAIL, "|-");
local $SIG{ALRM} = sub { CORE::exit; };
unless (defined $pid) {
# fork failed!
return "Error sending mail.";
}
if ($pid) {
# parent
$from = "$name <$from>" if defined $name;
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n\n";
print MAIL $message, "\n";
close MAIL;
return 1;
} else {
# child
exec("/var/qmail/bin/qmail-inject", "-f", $from, "--", $to)
|| CORE::exit;
}
}
--
Roger Espel Llima, [EMAIL PROTECTED]
http://www.iagora.com/~espel/index.html