I'm working on a script to do a very specific thing, take in an online form with a file attachment and then formats it back out as an html email that displays in Lotus notes for printing. Obviously, this is an internal client need. Anyway, I'm using the CGI.pm module and MIME::Lite to send the multipart message. This is my first time using MIME::Lite and I'm having trouble figuring out how to build the html part of the message with variables. The way I've done in the past would be something like:
sub send_email { open (MAIL, "|$mailprog -t") || die "Can't open $mailprog!\n"; print MAIL "Content-type:text/html\n"; print MAIL "From: $from_email\n"; print MAIL "To: $to_email\n"; print MAIL "Subject: $attention Employment Application : $fields{'n +ame'}\n\n"; print MAIL <<to_the_end; <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> to_the_end close (MAIL); }
Which worked great and would insert form variable values ($name in this example) into the email body. Now I'm trying to use
sub Email_Results{ my $message = ' <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>'; $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 => $message); $msg->attach(Type => 'application/octet-stream', Path => "$Directory/$File_Name", Filename => $File_Name ); $msg->send(); }
and instead of printing out the value of $name, it just prints $name literally. I've been reading all over the place and everything just points to using the $message variable for the email, but how do I build the $message variable with other variable values? Is there anything similar to the print <<to_the_end; functionality for MIME? TIA

In reply to MIME::Lite $message construction with variables by hmbscully

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.