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

That cleared some issues for me for sure, thank you, but the images is still only showing when the $->attach(); is inside of sub email for some reason.
  • Comment on Re^2: Attaching images to email html template help!

Replies are listed 'Best First'.
Re^3: Attaching images to email html template help!
by Eliya (Vicar) on Mar 17, 2011 at 17:50 UTC
    but the images is still only showing when the $->attach(); is inside of sub email

    To attach the images you need the $msg object, and as you have it, that object is lexically scoped to your email function.

    Anyhow, why do you want to attach the images outside of the function?

      Eventually I will change the email sub into a module so I can use it with another scripts I have. But that will be another battle!
Re^3: Attaching images to email html template help!
by Anonymous Monk on Mar 17, 2011 at 17:47 UTC
    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?
      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' } ];