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

Dear Perlmonks, I have an Informix web interface that does some form processing for me and I've got a chunk that does mailing of form results that looks like this:
/^MAIL/ && do { $text = $execute; $syscmd = "echo $text $attributes{MSG} |mail $attributes{EADD} +"; system ( $syscmd ); last SWITCH; };
Unfortunately when it runs, I get email that has no subject matter. Could someone out there assist me in making this add a subject line? I've also tried using mailx with the -s switch, but that doesn't seem to work either. Any ideas?

Replies are listed 'Best First'.
Re: Informix ouput mailed without subject?
by Fastolfe (Vicar) on Oct 25, 2000 at 22:43 UTC
    Your "mail" message should probably contain message headers like "Subject" or "From" to give more descriptive information about the nature of the message. Follow these headers with a blank line and then with your message text.

    Depending upon where $execute and %attributes are built, your mail method has a huge potential security problem, as anyone could seed these variables with a harmful string, which would be dutifully parsed by your shell interpreter via your system call.

    A far more useful approach to doing all of this is to use any of the stock e-mail modules already in existence and send your message through one of them. See How do I send e-mail from my Perl Program? and How do I send an email with Perl (including an attachment)? for more information.

Re: Informix ouput mailed without subject?
by kilinrax (Deacon) on Oct 25, 2000 at 22:43 UTC
    Unless you're determined not to use modules, I'd use Mail::Mailer;
    if (/^MAIL/) { sendmail ($mailfrom, $mailto, $subject, $body); } sub sendmail { my ($from, $to, $subject, $body) = @_; my $mailer; eval { $mailer = Mail::Mailer->new('sendmail'); }; if ($@) { warn "Couldn't send mail: $@"; } else { $mailer->open({ From => $from, To => $to, Subject => $subject }); print $mailer $body; unless (close ($mailer)) { warn "Couldn't close mailer: $!"; } } }