mail function problem

Hello all,

I'm attempting to sent an e-mail with the following funtion in my script. The tested that the logic is correct with another native os command, but I can't seem to get mail to work. I played with the "", just can't seem to get it right. Any ideas? Thanks.

$my_mail = `mail -s`;

sub mail {

    $my_mail "test" [email]my.name@company.com[/email] < /dev/null;

    \}

db_util.pl" 59 lines, 869 characters
./db_util.pl
String found where operator expected at ./db_util.pl line 57, near "$my_mail "test""
(Missing operator before "test"?)
Bareword found where operator expected at ./db_util.pl line 57, near ""test" my"
(Missing operator before my?)
Array found where operator expected at ./db_util.pl line 57, at end of line
Bareword found where operator expected at ./db_util.pl line 57, near "/dev/null"
(Missing operator before null?)
syntax error at ./db_util.pl line 57, near "$my_mail "test""
Execution of ./db_util.pl aborted due to compilation errors.

You have the quotes the wrong way, and don't put a dollar sign when declaring a variable. Also no spaces around the equals sign. The shell is a harsh mistress.

my_mail='mail -s'

era, it's a perl script, not shell.

Oops! Egg on my face.

Still, you can't invoke it like that; the backticks evaluate there and then, which is not what you want. And, you can't pass parameters like redirection like that in a Perl script.

sub mail
{
  open (MAIL, '| mail -s "test" spamtrap@example.com') || die "anguish: $!";
  close MAIL;
}

There are simpler ways but eventually I guess you will be wanting to print MAIL something between the open and close, and not just send an empty message.

you can try the examples here
perldoc -q mail