nujersedvl has asked for the wisdom of the Perl Monks concerning the following question:

this is a program i have that sends a list of people an email. the problem is that when a bogus address is entered, the error message does not bounce back to the sender.
#!/usr/local/bin/perl use CGI; $foo = new CGI; $recips = $foo->param('recipient'); $realname = $foo->param('realname'); $realemail = $foo->param('realemail'); $mailprog = '/usr/sbin/sendmail'; my $rhost = $ENV{"REMOTE_HOST"} || "unknown"; my $raddr = $ENV{"REMOTE_ADDR"} || "unknown"; @recipients = split("\, ", $recips); if(defined ($val = $foo->cookie(-name => "sent-mail"))) { print $foo->header(); print " <body bgcolor=\"#FFCC00\"> <p align=\"center\"><big><big><strong><font face=\"Arial\">Sorry $real +name, emails can only be sent once.</font></strong></big></big></p> </body>"; } else { foreach $person (@recipients) { ($pname, $pemail) = split("\<", $person); $pemail =~ s/\>.*//; $pname =~ s/\s+//; open(MAIL,"|$mailprog -t"); # use mailer-friendly "x headers" print MAIL "X-REMOTE_HOST: $rhost\n"; print MAIL "X-REMOTE_ADDR: $raddr\n"; print MAIL "To: $pemail\n"; print MAIL "Reply-To: $pemail\n"; print MAIL "From: $realemail ($realname)\n"; print MAIL "Subject: $pname, interesting site\n\n"; print MAIL " $pname message $realname"; close (MAIL); } open(FILE, ">> addresses.txt"); @addresses = <FILE>; foreach $person (@recipients) { ($pname, $pemail) = split("\<", $person); $pemail =~ s/\>//; if($pemail !=~ /\s+\,\s+/) { print FILE "$pemail\n"; }} close(FILE); print $foo->header(); $cookie = $foo->cookie('-name' => "sent-mail", '-value' => "sent"); print " <body bgcolor=\"#FFCC00\"> <script language=javascript> alert(\"Thank you for using the reminder service\"); open(\".../blank.html\", target=\"h_window\"); </script> </body>"; }

Replies are listed 'Best First'.
Re: mail error response
by lhoward (Vicar) on Apr 10, 2001 at 05:24 UTC
    That is because you never set the sender address. I believe that adding the following line to your code may do it (I'd need to dust off my "pipe to sendmail" hat to say for certain).
    print MAIL "Sender: addrtogetbounces\@example.com\n";
    You could solve this problem and enable for better error checking if you used SNMP to send the message, instead of forking a pipe to a sendmail process. There are sevearl good modules to use to do this : Net::SMTP, Mail::Sendmail, even MIME::Lite has this capability...
      I think something like :

      print MAIL "From: addrtogetbounces\@example.com\n";

      might be better

      Greetz
      Beatnik
      ... Quidquid perl dictum sit, altum viditur.
        neither fix seems to work. no error response messages are sent. thanks for any more help. steve