I’m trying to write a Perl script which writes to a file and then uses linux’s mail command to send whatever the Perl script wrote to the file.
My code is the following:
my $pathfile='some_pathfile';
open(W_VAR,">>$pathfile");
print W_VAR 'hello';
close W_VAR;
my $email_command='mail -s'." header".' some_email_address'.' <'." $pathfile";
system($email_command);
The problem is that the content in the pathfile never gets sent.
If I personally fill out that file, all is fine, but whatever perl has written is simply not sent. The content is in the file when i check though.
What is the problem?
I suspect the problem is that your program doesn’t terminate the line with a newline
"\n"character. No doubt you put one into the file when you edited it manually?Something like this may fix it, but I don’t have a Linux box to hand so I can’t test it.
Edit
But it would be far nicer to use something like Mail::Sendmail. Email::Sender is by far the best, but together with its dependencies it is a huge module for so simple a task and I hesitate to recommend it here.
The code to use
Mail::Sendmailwould look like this: