Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

MIME::Lite::TT::HTML problems

by jonnyfolk (Vicar)
on Feb 27, 2008 at 09:39 UTC ( #670560=perlquestion: print w/ replies, xml ) Need Help??
jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

I have used this module as follows to send an html file, which works fine. (Appreciation to ides for his article/tutorial):
#!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; use MIME::Lite::TT::HTML; my %params; foreach my $name (param( )) { $params{$name} = param($name); } my $host_serv = '/path/host_serv.pdf'; my $prem_serv = '/path/prem_serv.pdf'; my %options; # $options{INCLUDE_PATH} = '/path/to/templates'; my $msg = MIME::Lite::TT::HTML->new( From => 'ex@why.com', To => $params{'emailto'}, Subject => 'Your recent purchase', Template => { html => 'test.html.tt', }, TmplOptions => \%options, TmplParams => \%params, ); $msg->send;
However when I add 'attach' to the code, the attachment is sent but the html message is not. When I add TWO attachments only the last is sent, but without the html message (below). Obviously what I am doing is overwriting $msg each time, which I don't want to do. Can anyone show me how to get this done?
#!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; use MIME::Lite::TT::HTML; my %params; foreach my $name (param( )) { $params{$name} = param($name); } my $host_serv = '/path/host_serv.pdf'; my $prem_serv = '/path/prem_serv.pdf'; my %options; # $options{INCLUDE_PATH} = '/path/to/templates'; my $msg = MIME::Lite::TT::HTML->new( From => 'ex@why.com', To => $params{'emailto'}, Subject => 'Your recent purchase', Template => { html => 'test.html.tt', }, TmplOptions => \%options, TmplParams => \%params, ); $msg->attach( Type => 'application/pdf', Path => $host_serv, Filename => 'host.pdf', Disposition => 'attachment' ); $msg->attach( Type => 'application/pdf', Path => $prem_serv, Filename => 'guest.pdf', Disposition => 'attachment' ); $msg->send;

Comment on MIME::Lite::TT::HTML problems
Select or Download Code
Re: MIME::Lite::TT::HTML problems
by tirwhan (Abbot) on Feb 27, 2008 at 15:09 UTC

    All the message parts you expect are being sent (check the "source text" of the mails in your mail client and you'll see the attachments), but your mail client isn't showing them because MIME::Lite::TT::HTML sets the Content-Type to "multipart/alternative". Set it to "multipart/mixed" manually and you should see the attachments.

    ... my $msg = MIME::Lite::TT::HTML->new( From => 'ex@why.com', To => $params{'emailto'}, Subject => 'Your recent purchase', Template => { html => 'test.html.tt', }, TmplOptions => \%options, TmplParams => \%params, ); $msg->attr("content-type" => "multipart/mixed"); ...

    All dogma is stupid.
      That fixed it in an instant!!
      Thanks very much for pointing that out, tirwhan - it's been driving me to distraction!! Much appreciated...
      Fantastic. This answer just saved me a lot of time! Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://670560]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (14)
As of 2014-09-18 19:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (121 votes), past polls