in reply to Re^2: Attaching images to email html template help!
in thread Attaching images to email html template help!

I got it to work, the issue was with ID => 'logo',".
It should be;
Id => 'logo',

I am curious about how I could fill the hashes dynamically, any example on that?

Replies are listed 'Best First'.
Re^4: Attaching images to email html template help!
by Eliya (Vicar) on Mar 17, 2011 at 18:03 UTC
    I am curious about how I could fill the hashes dynamically

    That largely depends on where you get the info from.  Let's say you read a list of image paths from a file  (__DATA__ here):

    #!/usr/bin/perl -w use strict; my @imgs; while (my $path = <DATA>) { chomp $path; my ($fullname, $name, $ext) = $path =~ m#(([^/]+)\.(\w+))$#; my $type = "image/$ext"; $type =~ s/jpg$/jpeg/; push @imgs, { Type => $type, ID => $name, Path => $path, Filename => $fullname, Disposition => 'attachment', }; } use Data::Dumper; print Dumper \@imgs; __DATA__ /images/logo.gif /images/footer.gif /images/whatever.gif

    produces:

    $VAR1 = [ { 'ID' => 'logo', 'Disposition' => 'attachment', 'Type' => 'image/gif', 'Filename' => 'logo.gif', 'Path' => '/images/logo.gif' }, { 'ID' => 'footer', 'Disposition' => 'attachment', 'Type' => 'image/gif', 'Filename' => 'footer.gif', 'Path' => '/images/footer.gif' }, { 'ID' => 'whatever', 'Disposition' => 'attachment', 'Type' => 'image/jpeg', 'Filename' => 'whatever.jpg', 'Path' => '/images/whatever.jpg' } ];