I'm trying to read the contents of a file (message.txt), put them in a mail and then mail it
This is what I have thus far but I having trouble referencing the file. I'm trying to put it into an array so any ideas would be helpful ...
$to='user.n@domain.com';
$from= 'username';
$subject='Test';
my $log_file = "/message.txt";
open FILE, "$log_file" or die $!;
my @array_of_data = <DATA>;
open(MAIL, "|/usr/sbin/sendmail -t");
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL <DATA>;
close(MAIL);
close FILE;
close (DATA);
print "A message has been sent from $from to $to\n";
#!/usr/bin/env perl
use warnings;
use strict;
my $to = 'user.n@domain.com';
my $from = 'username';
my $subject = 'Test';
my $log_file = '/message.txt'; # are you sure it's /message
# and not ./message?
my $file_content;
{
local $/ = undef;
open FILE, '<', $log_file or die "open $log_file: $!\n";
$file_content = <FILE>;
close FILE or warn "close $log_file: $!\n";
}
open MAIL, "|/usr/sbin/sendmail -t";
## Mail Header
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n\n";
## Mail Body
print MAIL $file_content;
close MAIL;
print "A message has been sent from $from to $to\n";