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

The following email program will work when the text being sent to sendmail is quoted with a HEREIS but not when it's quoted with either qq or "". Using qq or "" results in the message "No recipient addresses found in header." I tried adding newlines after each line in the header, but it didn't make a difference. Anyone know why this is?

(if you replace the qq with a HEREIS, this will work)

open(MAIL, "|/usr/lib/sendmail -oi -t") || die "Can't open sendmail: $ +!"; print MAIL qq| From: Me <me\@here.com> To: You <you\@there.com> Subject: Email body text|; close(MAIL);
Thanks!

Replies are listed 'Best First'.
Re: Sendmail and qq vs HEREIS
by dvergin (Monsignor) on Jun 27, 2001 at 04:40 UTC
    If you use a HERE doc, the quoted portion starts with the text on the next line. And all is well.

    Using qq as you have (or "), you are including an initial newline character with nothing before it. This looks like an empty line to the mail program and makes it think you are already done with the header. But that "everything up to an empty line" header is empty!

    So how about:

    print MAIL qq|From: Me <me\@here.com> To: You <you\@there.com> Subject: Email body text|;
    ...or some such. HTH
Re: Sendmail and qq vs HEREIS
by bikeNomad (Priest) on Jun 27, 2001 at 04:43 UTC
    The way you have it written, there's an extra newline before the From: line, which will probably cause problems (you don't want a blank line in your headers). Have you tried:

    open(MAIL, "|/usr/lib/sendmail -oi -t") || die "Can't open sendmail: $ +!"; print MAIL qq|From: Me <me\@here.com> To: You <you\@there.com> Subject: Email body text|; close(MAIL);
(tye)Re: Sendmail and qq vs HEREIS
by tye (Sage) on Jun 27, 2001 at 09:49 UTC

    Kudos to the previous fine answers. (: But also note that your qq solution omits the very last newline and this may also cause you problems.

            - tye (but my friends call me "Tye")