Pipe

The unix piping concept is illustrated below using the unix sendmail function. This function is used because it is a little simpler than the other direct going email to script. Also because sendmail can be a little tweaky. The following code was tested to work on dreamhost so you can use it if you are finding subject lines being left out or mysterious errors flagging unknown recipients.

sub ScriptToEmail { my ($recipient, $subject, $text, $fromfield) = @_; my $mailprog = "/usr/sbin/sendmail"; open MAIL, "| $mailprog -t -oi"; print MAIL "To: $recipient \n"; print MAIL "From: $fromfield \n"; print MAIL "Reply-To: $fromfield \n"; print MAIL "Subject: $subject \n"; print MAIL "\n"; print MAIL "$text"; print MAIL "\n"; close MAIL; return ; }

You can see the pipe function occuring in the line with: open MAIL, "| $mailprog -t -oi"; Piping allows you to feed the standard input/output stream into a UNIX function. First you print into the file MAIL which in reality is a standard output stream piped into the sendmail function. Notice the UNIX function must be triggered to run by this piping function.