in reply to Re: How do I send mail from a script?
in thread How do I send mail from a script?

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
3Re: How do I send mail from a script?
by jeffa (Bishop) on Aug 08, 2003 at 14:08 UTC
    RTFM stands for "Read The Fine Manual". Some people prefer an expletive for the third word ... but the point is that you should have read the docs for Mail::Mailer:
    ARGUMENTS
    
    "new" can optionally be given a $command and $type.  $type
    is one "sendmail", "mail", ... given above.  The meaning
    of $command depends on $type.
    
    "open" is given a reference to a hash.  The hash consists
    of key and value pairs, the key being the name of the
    header field (eg, "To"), and the value being the
    corresponding contents of the header field.  The value can
    either be a scalar (eg, "gnat@frii.com") or a reference to
    an array of scalars ("eg, ['gnat@frii.com',
    'Tim.Bunce@ig.co.uk']").
    
    So ... here is how i would write your code snippet:
    use Mail::Mailer; my @param = qw( Title Name Position School Address Suburb State PCode Email Tel Fax Att1 Att2 Att3 Att4 Att5 Att6 Att7 Att8 Att9 Comments ); my $mailer = Mail::Mailer->new; $mailer->open({ To => 'foo@bar.com', From => 'baz@qux.com', Subject => 'results of submit', }); my $body; $body .= "$in{$_}\n" for @param; print $mailer $body; $mailer->close;
    Hope this helps. :)

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Hey man. Thanks for giving me a hand. Tried your code but recieved the following error: Global symbol "%in" requires explicit package name at enquiry02.pl line 23. I have no idea what it means. Any idea? Here is my code so far
      #!/usr/bin/perl -w use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Mail::Mailer; my @param = qw( Title Name Position School Address Suburb State PCode Email Tel Fax Att1 Att2 Att3 Att4 Att5 Att6 Att7 Att8 Att9 Comments ); my $mailer = Mail::Mailer->new; $mailer->open({ To => 'pete@home.com', From => 'Tester@qux.com', Subject => 'results of submit', }); my $body; $body .= "$in{$_}\n" for @param; print $mailer $body; $mailer->close;
        Yep, you didn't declare %in and since you are using strict, this causes a compilation error. I recommend you add this at the top:
        use CGI qw(:standard); use vars qw(%in); CGI::ReadParse();
        The use vars declares %in as a global variable (you could probably also use our). Personally, i prefer using CGI::param() instead of CGI::ReadParse() - you could construct $body like this instead:
        $body .= param($_) . "\n" for param;
        instead, or if you only want the form fields listed in the @param array:
        $body .= param($_) . "\n" for @param;
        Hope this helps more. :)

        jeffa

        L-LL-L--L-LL-L--L-LL-L--
        -R--R-RR-R--R-RR-R--R-RR
        B--B--B--B--B--B--B--B--
        H---H---H---H---H---H---
        (the triplet paradiddle with high-hat)