Lunarpages Web Hosting Forum

Scripting Languages Hosting Help => C++ / PERL / CGI Support => Topic started by: turula2 on October 15, 2015, 07:58:20 AM

Title: using sendmail in perl
Post by: turula2 on October 15, 2015, 07:58:20 AM
I have a short perl  program that sends me an email whenever a specific page is hit on my web site.  This ha worked fine for about ten years until about sept 15 (2015) when it stopped working.  Anyone know what may have changed at that time.

Is there a better place to ask this question.  This sub-forum seems to get about one query per year.

The script is:

open (MAIL,"|/usr/sbin/sendmail -t");
      print MAIL "To: address\\n";
      print MAIL "From: address2\ (Web Hit xxx)\n";

      $_=$ENV{HTTP_REFERER} ;
      s  ? ;
      print MAIL "Subject: $ENV{REMOTE_ADDR}  $ENV{QUERY_STRING}  $_ $count\n\n";
      print MAIL "$ENV{REMOTE_ADDR}\n" ;
 close (MAIL);

I don't really know perl.  I know this is being executed because the counter does get incremented.

Title: Re: using sendmail in perl
Post by: MrPhil on October 15, 2015, 02:08:58 PM
I haven't used Perl for Web page stuff, so just some guesses here. LP has been upgrading servers over the last month or so, and it's possible that some code (of yours) that was legal before is now a problem (security issues, etc.). Without some sort of error message telling you why it failed, "it stopped working" doesn't leave much to go on. Nothing at all comes through, or just bad email content? No error messages embedded in the email, or on the screen, or in some sort of log file (like PHP does with error_log)?

I seem to recall seeing reports in various places of email getting stricter about its formatting, and in some place \n might now have to be \n\n and vice-versa. I wouldn't go randomly changing anything, though, until you've done some research. I'm not sure that " (Web Hit xxx)" is legitimate in a "From" field -- you might try removing it or moving it into the body. Maybe that's what's hanging you up now.

The Perl code looks fairly clean. It opens a file handle MAIL which is piping content to the sendmail command. You might double-check that /usr/sbin/sendmail hasn't been moved to some other place, or accidentally lost during an upgrade (open a support ticket). The "To" and "From" address lines are sent. $_ is a variable assigned the HTTP_REFERER field, and (the first) "" is replaced by a "-". A big "Subject" line is assembled with the REMOTE_ADDR, QUERY_STRING, modified HTTP_REFERER, and the count. Finally, the body of the email appears to be just the REMOTE_ADDR. You might think about debugging this by print "$_\n"; etc. to dump the variables on-screen (temporarily) and see if everything looks like it's there, with reasonable content.

I take it this is just a fragment of the entire Perl code, as $count must be set somewhere. Good luck with debugging!
Title: Re: using sendmail in perl
Post by: turula2 on October 15, 2015, 10:15:01 PM
MrPhil:  Thanks for looking into this and for your response.  I've tried many of the suggestions in your third paragraph and that didn't solve the problem.  But I did get it to work and it's your second paragraph that identifies the problem (I think).  Apparently the  "From: "  format that I used was acceptable before the mid September server upgrade but not after.  The email format  "address (alias)"  was not uncommon 10 year ago, but is pretty rare these days (I still get some UK email so formatted, but not US email).  The common format these days is  "alias <address>".  When I deleted that " (Web Hit xxx)" part it started working again.  Again, thanks for looking into this for me.
Title: Re: using sendmail in perl
Post by: MrPhil on October 16, 2015, 05:08:30 AM
Hooray! Glad to have helped.

You might be able to use Web Hit xxx <real address> in the "From" line, but no promises. It might affect how that email address gets reused in the future (if it is ever reused). That information might better be in the subject line or the body of the email.
Title: Re: using sendmail in perl
Post by: turula2 on October 16, 2015, 06:09:31 AM
Yes, your suggestion does works.  I tested it.  But I don't need to have any text besides the "real address".  It turns out that the real address does NOT need to be a real address.  As long as it's it will work.  That's a bit of a surprise because I'd expect that "sendmail" would at least check that the "From:" email is a real email account or forwarder defined in my domain on the server.  Again, thanks for looking into this.