in reply to MAIL::SENDMAIL - Inserting $variable Into TO or FROM?

It would appear that you updated your OP (without indicating such) following Laurent_R's initial response. I was unaware that you had made this update when I initially responded. You now appear to have updated the OP again: there's still no indication of what exactly you've changed.

Laurent_R has pointed out how this makes the thread problematic. "How do I change/delete my post?" has full details of how to update a node and why you should do it this way. Please edit your OP such that it accurately reflects the changes you have made.

Casting my mind back a couple of decades, "Matthew Wright's FORMMAIL" was written for Perl4 and '@' characters were not treated specially in strings in Perl4.

I've already provided a list of things you could do to help with your problem and also to help us to help you. Despite sending me a PM with "Please the update to my post which answers some of the points you mentioned. Any further advise will be appreciated.", I see little evidence that you've actioned any of those points. Perhaps deal with the advice already given before asking for more.

-- Ken

Replies are listed 'Best First'.
Re^2: MAIL::SENDMAIL - Inserting $variable Into TO or FROM?
by Milti (Beadle) on Jan 22, 2014 at 17:21 UTC
    Hi to all who have responded. Ken provided the answer. The '@' character in the email addresses was the problem. In a trial I used a \ to escape the @ and the value was interpolated. Thanks to all who responded to my question! Milti
      Yes, this issue with the @ in the address is exactly what I had in mind when I specified:

      including how you are defining the variables that you later use for your sender, recipient

      I thought that this was a likely cause for your problem.

      Glad anyway that you solved it.

      Can you please show your corrected code? Thanks in advance.

        Here's the code:

        #!/usr/bin/perl -w ###use strict; use DBI; use CGI qw(:standard); print "Content-type: text/html\n\n"; @referers = ('72.167.40.203','www.mywebsite.com','mywebsite.com'); &check_url; &mail; sub check_url { local($check_referer) = 0; if ($ENV{'HTTP_REFERER'}) { foreach $referer (@referers) { if ($ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$referer|i) +{ $check_referer = 1; last; } } } else { $check_referer = 1; } if ($check_referer != 1) {&bad_referer} } sub bad_referer { print "content-type: text/html\n\n"; print <<"(END ERROR HTML)"; <html> <head> <title>Bad Referrer - Access Denied</title> </head> <body bgcolor=#FFFFFF text=#000000> <center> <table border=0 width=600 bgcolor=#9C9C9C> <tr><th><font size=+2>Bad Referrer - Access Denied</font></th></tr +> </table> </center> </body> </html> (END ERROR HTML) exit; } sub mail { ###Get the name, email address, and profile address of the sender my ($dbh, $sth, $count, $AccountID,$SenderFirstName, $SenderLastName, +$SenderEmail, $ID, $row, $View); $dbh = DBI->connect('dbi:mysql:membersdb','ID','pw') or die "Connection Error: $DBI::errstr\n"; my $SenderID = param('SenderID'); $sth = $dbh->prepare("SELECT FirstName,LastName,Email,View FROM member +info WHERE AccountID='$SenderID'"); $sth->execute (); my @row = $sth->fetchrow_array (); $SenderFirstName= $row[0]; $SenderLastName= $row[1]; $SenderEmail= $row[2]; $SenderView= $row[3]; $sth->finish; ##Get the name & email address of the recipient my ($dbh, $sth, $count, $AccountID,$FirstName, $LastName, $Email, $row +); $dbh = DBI->connect('dbi:mysql:membersdb','ID','pw') or die "Connection Error: $DBI::errstr\n"; my $ID = param('AccountID'); $sth = $dbh->prepare("SELECT FirstName,LastName, Email FROM memberinfo + WHERE AccountID='$ID'"); $sth->execute (); my @row = $sth->fetchrow_array (); $FirstName= $row[0]; $LastName= $row[1]; $Recipient= $row[2]; $sth->finish; $dbh->disconnect (); use HTML::Entities; use Mail::Sendmail 0.79; my $Message = param('Message'); $From="info\@mywebsite.com"; $html = <<END_HTML; <p>$SenderFirstName $SenderLastName has sent you a message.</p> <p>$Message</p> <form method="POST" action="http://www.mywebsite.com/cgi-bin/global/cr +eate_reply_mail_htm.pl?ID=$SenderID"> <p>Reply to $SenderFirstName --- <input type="submit" value="REPLY" na +me="B1" style="color: #FFFFFF; background-color: #0000FF"> </p> </form></p> END_HTML %mail = ( from => "$From", to => "$Recipient", subject => 'A Message From My Website', '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"; ###} &redirect; exit (0); sub redirect { print "Your Message Was Sent\n\n"; } exit; }
        $FROM is a constant so the '@' sign was simply escaped with a \. Other variables are sent from forms and everything works fine with the above code with the param function. I do have another question. Where do I find information as to how to get CGI.pm to accept either POST or GET methods? Is there a smidgen of code to use?