#!/usr/bin/perl use strict; use warnings; use MIME::Lite::TT::HTML; my %params; $params{first_name} = 'Joe'; $params{last_name} = 'Test'; $params{date} = 'April 11, 2011'; my %options; $options {INCLUDE_PATH} = '/templates'; my $logo = '/images/logo.gif'; my $footer = '/images/footer.gif'; # I'd like to have a system that would allow me # to add as many images as possible to my template file here # instead of multiple hashes, is that possible? my %img_in; $img_in{Type} = 'image/gif'; $img_in{Id} = 'logo'; $img_in{Path} = $logo; $img_in{Filename} = 'logo.gif'; $img_in{Disposition} = 'attachment'; my %img_sec; $img_sec{Type} = 'image/gif'; $img_sec{Id} = 'footer'; $img_sec{Path} = $footer; $img_sec{Filename} = 'footer.gif'; $img_sec{Disposition} = 'attachment'; # set up email my $to = 'test@test.com'; my $from = 'test@test.com'; my $subject = "Email Sent Test"; my $message = "Email Test."; # send email email($to, $from, $subject, $message); # email function sub email { # get incoming parameters my ($to, $from, $subject, $message) = @_; # create a new message my $msg = MIME::Lite::TT::HTML->new( From => $from, To => $to, Subject => $subject, Template => { #text => 'test_txt.tt', html => 'test_html.tt', }, TmplOptions => \%options, TmplParams => \%params, Data => $message ); # add the attachments # this works but I need these values to be dynamic not hard coded in here =code my $logo = '/images/logo.gif'; my $footer = '/images/footer.gif'; $msg->attach( Type => 'image/gif', Id => 'logo', Path => $logo, Filename => 'logo.gif', Disposition => 'attachment' )or die "Error adding $logo: $!\n"; $msg->attach( Type => 'image/gif', Id => 'footer', Path => $footer, Filename => 'footer.gif', Disposition => 'attachment' )or die "Error adding $footer: $!\n"; =cut # here is where I am having problems for ( keys %img_in ) { $msg->attach( Type => $img_in{Type}, Id => $id=$img_in{ID}, Path => $path=$img_in{Path}, Filename => $img_in{Filename}, Disposition => $img_in{Disposition} )or die "Error adding $img_in{$_}: $!\n"; } # send the email $msg->send(); } #### TEST HTML
Logo:
Hi [% first_name %],

Last Name [% last_name %].

[% date %]

Thank you!

Logo Footer: