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

When trying to manually send email, I am returned the error...

"No recipient addresses found in header"

Anyone care to take a peek at the code and show me the err of my ways?
open(SENDMAIL, "|/usr/sbin/sendmail -oi -t") or die "Cannot fork for sendmail: $!\n"; print SENDMAIL qq^ From: Monitor <root\@host.domain.com> To: Pen Quin <penguinfuz\@another-domain.com> Subject: $hostname Monitoring Script Hello, I am the monitoring script for $hostname. ^; close(SENDMAIL) or warn "Oops, sendmail did not close properly\n";

Replies are listed 'Best First'.
Re: Manually sending email.
by VSarkiss (Monsignor) on Jun 13, 2001 at 06:30 UTC
    The header lines have to be flush-left (i.e., preceded by newlines). You've got white space in front of them. Try:
    print SENDMAIL qq^ From: Monitor <root\@host.domain.com> To: Pen Quin <penguinfuz\@another-domain.com> Subject: $hostname Monitoring Script Hello, I am the monitoring script for $hostname. ^;
    BTW, the here-doc is just great for this kind of stuff:
    print SENDMAIL <<EOM; From: Monitor <root\@host.domain.com> To: Pen Quin <penguinfuz\@another-domain.com> Subject: $hostname Monitoring Script Hello, I am the monitoring script for $hostname. EOM
    Although it has the same white-space-preserving behavior. You can get around with some contortions, but it's a lot easier to just put everything flush-left.

    HTH <code

      Thanks alot, I'm using the here-doc method now and it works fine; However, even flushing the text to the left with my original method didn't help.

      Oh well, I guess "the why" will come to me with time, right now I'm happy with the "how".

      Thanks again!
        Your original method would still wind up with a blank return for the first line. The return you typed right after
        print SENDMAIL qq^
        like this...

        --
        $you = new YOU;
        honk() if $you->love(perl)