in reply to close statement issue

Perl variables are interpreted in here-documents. Therefore make sure your here-document data does not unintentionally contain candidates for variables, in particular '@$%' are tricky. Instead, incorporate them via literal strings:
open (MAIL,"| /usr/sbin/sendmail || die "$!";) my $to='joe@here.com'; my $from='smith@here.com'; print MAIL << "EOF"; To: $to From: $from Subject: data subject message body here EOF close MAIL || die "$!";

Replies are listed 'Best First'.
Re^2: close statement issue
by almut (Canon) on Mar 01, 2007 at 17:47 UTC

    ... or, escape the sigils:

    print MAIL << "EOF"; To: joe\@here.com From: smith\@here.com ... EOF

    or, use single quotes around the EOF:

    print MAIL << 'EOF'; To: joe@here.com From: smith@here.com ... EOF
      Thanks, I tried all suggestions and it still only works if I get rid of the close statement. Any other suggestions?

        Don't you get any more detailed error message than "mail not working"? (look in the syslog, MTA logfiles, etc.)

        Anyhow, something like this works fine for me (my incarnation of sendmail needs the -t option to read the addressees from the message headers...):

        #!/usr/bin/perl open MAIL, "| /usr/sbin/sendmail -t" or die "$!"; print MAIL << 'EOF'; To: joe@here.com From: smith@here.com Subject: data subject message body here EOF close MAIL or die "$!";