in reply to Re: Email Question
in thread Email Question

Now that strict and warnings are in place the $d is looking for an explicit package. How do I fix this?

Replies are listed 'Best First'.
Re^3: Email Question
by Corion (Patriarch) on Sep 24, 2015 at 20:32 UTC

    Why does it complain about $d but not about $PrStat ?

    See strict and my.

      Last Question.... Hopefully. close to the last line..
      system ('mail -s "Test" testmail@server.com, < DailyReport_$d.txt');
      I can send the email and I receive it but the subject does not show up. I have to me missing something simple.
        Do you get a subject if you issue the same command at the shell prompt?

        But this might probably be more a Unix/Linux question than a Perl question. Not all mail utilities have exactly the same syntax, may be your should check yours.

        A possible alternative might be something along these lines (I haven't tested exactly that, but only something similar):

        my $subject = "Mail subject\n"; my $from = 'me@my_company.com\n'; my $cc = "whoever\@my_company.com\n"; open my $MAIL, "|/usr/sbin/sendmail -t" or die "... $!";; # Mail Header print $MAIL "To: addressee\@my_company.com\n"; print $MAIL "Cc: $cc"; print $MAIL "From: $from"; print $MAIL "Subject: $subject\n\n"; # Mail Body print $MAIL "\nThe accompanying message to be sent.\n\n"; my $stat_file = "$result_path/STAT.TXT"; open my $COUNT, "<", $stat_file or die "can't open $stat_file $!"; print $MAIL <$COUNT>; close $COUNT; print $MAIL "\n\n\n"; print $MAIL "Regards, \n"; print $MAIL "sender's signature, \n"; close $MAIL;
        Having said that, it might well be better to use a mail module, such as Mail::Send, Mail::Sendmail or some other (there are many, and I really can't advise one against any other).

        I don't know why the subject wouldn't be set, but there are problems with your snippet as shown:

        Single quotes will not interpolate. I suggest you split up the line as:

        my $cmd = 'mail -s "Test" testmail@server.com, < DailyReport_$d.txt'; print "Running [$cmd]\n"; system($cmd) == 0 or warn "Couldn't run [$cmd]: $! / $?";

        That way, you will see that $d does not interpolate in your command line.

        You should swap the quoting style and always quote all the components:

        my $cmd = "mail -s 'Test' 'testmail\@server.com' < 'DailyReport_$d.txt +'";