in reply to MIME::Lite $message construction with variables

How bout something like this (untested but should work):
sub Email_Results{ $msg = MIME::Lite->new( From => 'net-admin@someplace.org', To => 'decoraw@someplace.org', Subject => 'Trying to send attachment', Type => 'multipart/mixed'); $msg->attach( Type => 'text/html', Data => << "EOHTML" <html> <head> <title>Human Resources : Application for Employment</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859 +-1"> </head> <body bgcolor="#FFFFFF" marginwidth="0" marginheight="0" class="margin +"> <table width="600" border="0"> <tr valign="top"> <td width="300"><font face="Arial, Helvetica, sans-serif" size=" +-1"> <b>Name:</b>&nbsp;<i>$name</i></font> </td> </tr> </table> </body> </html> EOHTML ); $msg->attach( Type => 'application/octet-stream', Path => "$Directory/$File_Name", Filename => $File_Name ); $msg->send(); }
Granted you could probably use some templating system to create the message for example Template Toolkit as shown in the introduction doc, pass the results to a variable then attach that to Data. Also if you use ' instead of " for quoting text you will not be able to interpolate variables (though with eval you could get back what you wanted as well)

-enlil

Replies are listed 'Best First'.
Re^2: MIME::Lite $message construction with variables
by drewbie (Chaplain) on Jun 11, 2004 at 03:20 UTC
    $msg = MIME::Lite->new( From => 'net-admin@someplace.org', To => 'decoraw@someplace.org', Subject => 'Trying to send attachment', Type => 'multipart/mixed');
    BTW, the "Type" param is not needed in the call to new(). When calling $msg->attach later, the object will automatically set the Type as needed. See the docs for more details.

    And I agree that MIME::Lite is definitely one of the coolest things since sliced bread. Major kudos to the author. I'm using it at work to mail out dynamically generated PDF's, and I think it took me all of 5 minutes after reading the docs to have working code. That's a well designed module. :-)