sub SendMemberMail { my ($subject,$from,$to,$port,$cc,$bcc,$heading,$body,$closing,$signiture,$auth) = @_; warn("In SendMemberMail before redirect of STDERR & STDOUT"); # Open log for recording during execution of SendMail my $sendMail_logfile = '/home/abcus/public_html/httpsdocs/cgi-bin/lib/perl/Mail/mail.log'; open (my $fh, "+<", "$sendMail_logfile") or die "Opening: $!"; #Redirect STDERR & STDOUT to $fh for this sub open my $oldSTDOUT, ">&STDOUT"; open OLDERR, ">&",\*STDERR; open (STDERR, ">>&=", $fh) || die "can't redirect STDERR"; open (STDOUT, ">>&=", $fh) || die "can't redirect STDOUT"; $fh->autoflush(1); my $message = ($heading . "\n" . "\n" . $body . "\n" . "\n" . $closing . "\n" . "\n" . $signiture . "\n" ); if ($auth == 1) { $auth = {user=>'webmaster@abc.us', password=>'xx@33333XX', method=>'PLAIN LOGIN', REQUIRED=>1} } elsif ($auth == 0) { $auth = ""; } my %mail = ( To => $to, From => $from, Cc => $cc, Bcc => $bcc, Auth => $auth, Port => $port, Subject => $subject, Message => $message, debug => 0 ); SendMail(%mail) or die $Mail::sendMail::error; $log .= "Sending eMail Succeded\n"; #Print the data from the $log. print $fh $log; #Test redirected handles print STDOUT "stdout 1\n"; warn("warn stderr 1\n"); close($fh); #restore the file standard handles open(STDOUT, ">&", $oldSTDOUT) or die "Can't dup \$oldout: $!"; open(STDERR, ">&OLDERR") or die "Can't dup OLDERR: $!"; #Test original handles print STDOUT "stdout 2\n"; warn("warn stderr 2\n"); return 1; }