I am trying to send an email in perl to myself and I can not get mailx to work correctly. Here is the whole perl file I have:
#!/usr/bin/perl
sub emailSender{
$RECIPIENT = "test\@test.com";
$FROM = "test\@test.com";
$SUBJECT = "test subject";
$BODY = @_[0];
open (MAIL, "|mailx -s \"$SUBJECT\" $RECIPIENT");
print MAIL $BODY;
close MAIL;
}
emailSender("This is a test");
I am not getting any errors or warnings when I run the script. It runs correctly but does not send an email. Am I missing something here? I can't find anything in the manual.
Tested OK (note mail -v
):
#!/usr/bin/perl
use strict; use warnings;
sub emailSender{
my $RECIPIENT = 'test@test.com';
my $FROM = 'test@test.com';
my $SUBJECT = "test subject";
my $BODY = shift;
open (MAIL, "|mail -v -s \"$SUBJECT\" $RECIPIENT");
print MAIL $BODY;
close MAIL;
}
emailSender("This is a test");
But for the coding style, I would keep UPPER CASE VARIABLES only for system or Perl internals
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.