There are several facets to your question. One is how to create an HTML table, and the other is how to generate and send an HTML formatted email. Below is some code that roughly accomplishes each of those tasks. Much could be done to improve the code further, but it should still enable you to get started.
use strict;
use warnings;
use MIME::QuotedPrint;
use HTML::Table;
use Mail::Sendmail;
# Read lines
open(FILE, 'log.txt') or die "Can't open File: File does not exist $!"
+;
my @file = <FILE>;
chomp @file;
@file = reverse(@file);
close FILE;
# Create Table
my $table = new HTML::Table;
$table->addRow(split /\s\s+/) for (@file[0..23]);
$table->setColBGColor(3, 'Green');
$table->setColFormat(1, '<font color="red">', '</font>');
$table->setColFormat(5, '<font color="blue">', '</font>');
# Create HTML email with table content
unshift @{$Mail::Sendmail::mailcfg{'smtp'}}, 'localhost';
my $plain = encode_qp "html log included";
my $html = encode_qp $table;
my $boundary = "====" . time() . "====";
my $date = Mail::Sendmail::time_to_date();
my %mail = (
From => 'me@localhost',
To => 'user@host.com',
Subject => "Report - Transfer Summary - $date",
'content-type' => "multipart/alternative; boundary=\"$boundary\"",
);
$mail{body} = <<END_OF_BODY;
--$boundary
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
$plain
--$boundary
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<html>$html</html>
--$boundary--
END_OF_BODY
# Send email and finish
sendmail( %mail ) or die "Error: $Mail::Sendmail::error\n";
printf "\nMail Sent @ $date\n";
Update
Here is more succinct code that uses a couple different CPAN modules to accomplish the goal:
use strict;
use warnings;
use HTML::Table;
use MIME::Lite;
use File::ReadBackwards;
my $table = new HTML::Table;
my $log = File::ReadBackwards->new('log.txt') or die $!;
$table->addRow(split(/\s\s+/, $log->readline)) for (1..24);
$table->setColBGColor(3, 'Green');
$table->setColFormat(1, '<font color="red">', '</font>');
$table->setColFormat(5, '<font color="blue">', '</font>');
$log->close;
my $msg = MIME::Lite->new(
From =>'me@localhost',
To =>'recipient@somewhere',
Subject =>'Transfer Summary',
Type =>'text/html',
Encoding =>'base64',
Data =>$table,
);
$msg->send;
|