Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Does anyone see something wrong with this? It's not erroring out, even with warnings and CGI CARP on..it just doesn't email. $sendmail is correct, $admin_mail is correct and so is $email.
open(MAIL, "| $sendmail") or die "Cannot open sendmail: $!"; print MAIL "To: $admin_mail\n"; print MAIL "From: $email\n"; print MAIL "Subject: dfg\n\n"; print MAIL "asd\n\n"; close(MAIL);

Replies are listed 'Best First'.
Re: sendmail not sending
by muntfish (Chaplain) on May 25, 2004 at 08:16 UTC

    I think you need to specify the recipient(s) on the command line, when using sendmail in this way. You might also want to consider the -i option, to stop it interpreting a . on its own as EOF:

    open(MAIL, "| $sendmail -i $admin_mail") or die "Cannot open sendmail: $!";

    You should, of course, check your local documentation for sendmail (man sendmail) for confirmation of this, as it may vary between Unix versions (I just did a quick test on HP-UX 11).

    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;
      You could also use the -t option to sendmail to tell it to get its recipients from the To: header.

        Aha, yes, that too. I'd forgotten that one - thanks.

        I'm surprised no-one has yet pointed out that piping to sendmail might not be the best way of sending a mail. I tend to prefer Net::SMTP as it is more portable.

        But it depends what the OP has available, or was trying to achieve, I guess.

        s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;