#!/usr/bin/perl use strict; use warnings; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); my $prog = '/usr/lib/sendmail'; my $to = 'Foo@nowhere.com'; my $from = 'Bar@somewhere.com'; my $file = 'report.txt'; my $num = 0; if ($ENV{QUERY_STRING} eq 'new' && -e $file) { unlink $file or die "Unable to remove '$file': $!"; } else { open(my $fh, '<', $file) or die "Unable to open '$file' for reading: $!"; $num = <$fh>; chomp $num; } my ($col, $n) = (2, 0); for my $i (1 .. $col) { $n = $i + $num; open (my $mail, '|-', $prog) or die "Unable to open a pipe to '$prog': $!"; gen_message($mail, $to, $from); } open(my $fh, '<', $file) or die "Unable to open '$file' for writing: $!"; print $fh $num + $col; close $fh; print header, start_html($num), $num, end_html(); sub gen_message { my ($mail, $to, $from) = @_; print $mail "Content-Type: text/plain; charset = windows - 1251\n"; print $mail "Subject: Text, Text!\n"; print $mail "To: $to\n"; print $mail "From: $from\n\n"; print $mail "Hello, the message text itself..\n"; print $mail "\n\n"; }