I've omitted to say that the qmail wrapper for sendmail works fine with Perl scripts. It doesn't work only with PHP (v4.1.2). Perl code is very identical with the PHP one. It opens a pipe to /var/qmail/bin/qmail-inject or "/usr/lib/sendmail -t", puts mail headers ending with "\n" and closes the pipe.
I think that the problem with closing the pipe in PHP causes the mail() function to return error, too.
I can't imagine what's wrong with qmail and PHP that it returns error on pipe closing and why such code works fine with Perl. Here is a Perl example:
open (MAIL,"| /usr/lib/sendmail -t");
print MAIL "To: $to\n";
print MAIL "From: $fromaddr\n";
print MAIL "Reply-to: $replyaddr\n" if $replyaddr;
print MAIL "X-Mailer: Perl Powered Socket Mailer\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message";
print MAIL "\n.\n";
close(MAIL);
Is there anybody familiar with the mail function in PHP?