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

I'd like to be able to send an email as HTML or as an attachment based on condition. So:

Content-Type: text/html
versus
Content-Type: text/html; name="form.htm"
Content-Disposition: attachment; filename="form.htm"

Currently I have 2 different functions because i can't figure out how do it conditionally. I can't stick an if statement within the body. It doesn't like that.

Replies are listed 'Best First'.
Re: I seek sendmail wisdome
by JavaFan (Canon) on Jan 26, 2011 at 16:46 UTC
    First of all, I wouldn't put headers like that in a here document, or another type of string. There are about fifty billion mail related modules on CPAN. There's got to be at least one doing what you want. I'd look at MIME::Lite.

    Second, why can't you put an if statement there?

    print <<"EOT"; ... @{[$foo ?"Blah blah bla" : "Other blah; more other blah"]} ... EOT
    Third, you don't need an if inside body, you can put it outside:
    my $headers = $foo ? "Blah blah bla" : "Other blah; more other blah"; print <<"EOT"; ... $headers ... EOT