Viljo Marrandi <[EMAIL PROTECTED]> said something to this effect on 08/16/2001:
> Can anyone tell how i can send mail from templates (to mail
> form data to somebody)? I need just a quick-hack right now to
> get it working (and to get the idea). And oh, i use
> Apache/mod_perl

I wrote a short Template plugin to do this:

# File: Template/Plugin/Sendmail.pm
package Template::Plugin::Sendmail;

use strict;
use base qw(Template::Plugin);
use vars qw($VERSION $log $error);

$VERSION = 0.10;

use Template 2.0;
use Template::Plugin;
use Template::Exception;

use Mail::Sendmail ();

*log   = *Mail::Sendmail::log;
*error = *Mail::Sendmail::error;

# new() isn't really used here, so it is basically empty
sub new { bless { _CONTEXT => $_[1] }, $_[0] }

# Here's the meat of it all:
sub sendmail {
    my $self   = shift;
    my $params = shift;

    Mail::Sendmail::sendmail(%{$params}) or
        die Template::Exception->new(__PACKAGE__, $log);

    return;  # Return nothing so that nothing is printed
             # by default.
}

sub error { $error }

1;
__END__

use it like:

[% USE m = Sendmail %]
[% m.sendmail( To   => "[EMAIL PROTECTED]",
               From => "[EMAIL PROTECTED]",
               Subject => "test",
               Body    => "hi",
        )
  %]

[% IF (m.error) %]Error: [% m.error %][% END %]

Take a look at the Mail::Sendmail docs to see what to pass to
Mail::Sendmail::sendmail().

(darren)

-- 
The Christian religion has been and still is the principal enemy of
moral progress in the world.
    -- Bertrand Russell


Reply via email to