Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: MAIL::SENDMAIL - Inserting $variable Into TO or FROM?

by Milti (Beadle)
on Jan 22, 2014 at 17:21 UTC ( [id://1071649]=note: print w/replies, xml ) Need Help??


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

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
  • Comment on Re^2: MAIL::SENDMAIL - Inserting $variable Into TO or FROM?

Replies are listed 'Best First'.
Re^3: MAIL::SENDMAIL - Inserting $variable Into TO or FROM?
by Laurent_R (Canon) on Jan 22, 2014 at 23:53 UTC
    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.

Re^3: MAIL::SENDMAIL - Inserting $variable Into TO or FROM?
by Laurent_R (Canon) on Jan 23, 2014 at 18:08 UTC
    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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1071649]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-09-15 06:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (21 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.