I'm using the following code to send messages:

sub send_mail { use HTML::Entities; use Mail::Sendmail 0.79; # doesn't work with v. 0.74! $FORM {'Message'}="GOOD MORNING!! It looks as if things are working!!" +; $Message="$FORM{'Message'}"; $FORM{'Sender'}="My Organization"; $sender="$FORM{'Sender'}"; $html = <<END_HTML; <p><strong>A MESSAGE FROM SOMEBODY</strong> <p>$FORM{'Sender'} has sent you a message.</p> <p>$Message</p> END_HTML %mail = ( To => 'somebody@somewhere.com', From => 'me@mysight.com' subject => 'A Message From Somebody', 'content-type' => 'text/html; charset="iso-8859-1"', ); $mail{body} = <<END_OF_BODY; <html>$html</html> END_OF_BODY sendmail(%mail) || print "Error: $Mail::Sendmail::error\n"; }
This works perfectly when email addresses are entered directly into the TO/FROM entities. However, I want to insert a $variable from a form into those slots. I have tried every combination that I can think of to accomplish that but nothing has worked. Can someone provide some guidance? Thanks for any assistance. I have tried the following at TO and FROM:
TO => $VAR, TO => "$VAR", TO => '$VAR', TO => $FORM{'recipient'}, TO => $FORM{recipient}, TO => "$FORM{'recipient}", TO => "$FORM{recipient}",
All without success. The interesting thing is that both $message and $FORM{'Sender'} are interpolated within the HTML message section of the code. $FORM {'recipient'}= "Somebody@somewhere.com"; and $VAR = "$FORM{'recipient}"; . I previously used an old version of Matthew Wright's FORMMAIL to process form input. It handled the following just fine:
sub send_mail { print "content-type: text/html\n\n"; %mail = ( To => "$FORM{recipient}", From => "$FORM{email}", Message => "$msg", Subject => "A Message From Somebody", ); sendmail(%mail) or die $Mail::Sendmail::error; }
The form variables were defined the same as above. Why won't the new code interpolate the variables as well?

In reply to MAIL::SENDMAIL - Inserting $variable Into TO or FROM? by Milti

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.