Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Here is the test template:#!/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(); }
<html> <body> TEST HTML<br> Logo: <img src="cid:logo" height="36" border="0"> <br> <strong>Hi [% first_name %]</strong>, <p> Last Name [% last_name %]. </p> <p> [% date %] </p> <p> Thank you! </p> Logo Footer: <img src="cid:footer" height="36" border="0"> <br> </body> </html>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Attaching images to email html template help!
by Eliya (Vicar) on Mar 17, 2011 at 17:15 UTC | |
by Anonymous Monk on Mar 17, 2011 at 17:42 UTC | |
by Eliya (Vicar) on Mar 17, 2011 at 17:50 UTC | |
by Anonymous Monk on Mar 17, 2011 at 17:54 UTC | |
by Anonymous Monk on Mar 17, 2011 at 17:47 UTC | |
by Eliya (Vicar) on Mar 17, 2011 at 18:03 UTC | |
by Anonymous Monk on Mar 18, 2011 at 13:30 UTC | |
by Eliya (Vicar) on Mar 18, 2011 at 13:54 UTC |