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?