我正在尝试用perl向自己发送一封电子邮件,但我无法让mailx正常工作。这是我的整个perl文件:
#!/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");
运行脚本时,我没有收到任何错误或警告。它运行正常但不发送电子邮件。我在这里错过了什么吗?我在手册中找不到任何内容。
答案 0 :(得分:2)
测试好(注意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");
但是对于编码风格,我会保留UPPER CASE VARIABLES仅用于系统或Perl内部