Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Duplicate mails with sendmail

Status
Not open for further replies.

JimJx

Technical User
Feb 16, 2001
202
US
Hi all,

I have 2 scripts that are sending email out through sendmail, one of them sends the mail 2X

I may be wrong here, but since I have one script that works fine, I am assuming that the problem has to be in the script itself, but being a novice with PERL, I cannot seem to find anything. If anyone can take a look at the code below and point me in the right direction or spot the problem, it would be a great help.

Thanks in advance,
Jim


Code:
#===== Send the card =====
sub send_card        {
   srand (time|$$);
    $userid = int (rand(1000));
    $userid .= "$$";

 open (PAGE, "$thank_you") || die ("I am sorry, but I was unable to open the file $thank_you.");
   while (<PAGE>)           {
        s/%%name%%/$input{'name'}/g;
        s/%%pickup%%/$pickup/g;
        print $_;      }
 close (PAGE);

 open (DATABASE, &quot;>>$cardlist&quot;) || die (&quot;I am sorry, but I was unable to open the file.&quot;);

#===== Remove any pipe symbols from input =====
    $input{'sender'} =~ s/\|//g;
    $input{'message'} =~ s/\|//g;
    $input{'name'} =~ s/\|//g;
    $input{'senderemail'} =~ s/\|//g;
    $input{'message'} =~ s/\s+/ /g;

    flock (DATABASE, 2);

      print DATABASE &quot;$userid\|$input{'sender'}\|$input{'senderemail'}\|$input{'message'}\|&quot;;
      print DATABASE &quot;$input{'name'}\|$input{'card_number'}\|$time\|$date\n&quot;;

    flock (DATABASE, 8);
 close (DATABASE);

#===== Send e-mail to recipient =====
 open (MAIL, &quot;|$mailprog $input{'address'}&quot;) || die &quot;Can't open $mailprog!\n&quot;;
        print MAIL &quot;Reply-to: $input{'senderemail'}\n&quot;;
        print MAIL &quot;From: $input{'senderemail'}\n&quot;;
        print MAIL &quot;To: $input{'address'}\n&quot;;
        print MAIL &quot;Subject: $subject\n\n&quot;;
 open (PAGE, &quot;$mail_message&quot;) || die (&quot;I am sorry, but I was unable to open the file $thank_you.&quot;);
        while (<PAGE>)                {
        s/%%sender%%/$input{'sender'}/g;
        s/%%userid%%/$userid/g;
        s/%%pickup%%/$pickup/g;
        s/%%company%%/$company/g;
        print MAIL $_;
        }
 close (PAGE);
 close (MAIL);
}

 
Try changing your sendmail part to

Code:
open(MAIL, &quot;| /usr/lib/sendmail -t&quot;) || die &quot;Error&quot;;
$r = select(MAIL); $|=1;

print &quot;To: $input{'address'}\n&quot;;
print &quot;From: $input{'reply-to'}\n&quot;;
print &quot;Subject: $subject\n&quot;;
print &quot;Reply-To: $input{'senderemail'}\n&quot;;
print &quot;Date: $d\n\n&quot;;

open (PAGE, &quot;$mail_message&quot;) || die (&quot;I am sorry, but I was unable to open the file $thank_you.&quot;);
        while (<PAGE>)                {
        s/%%sender%%/$input{'sender'}/g;
        s/%%userid%%/$userid/g;
        s/%%pickup%%/$pickup/g;
        s/%%company%%/$company/g;
        print $_;
        }
close (PAGE);
close(MAIL);

select($r);
}

What does input{'sender'} contain in your script?

Hope this helps,

Tim
--
Tim <tim@planetedge.co.uk>
 
Hi Tim,

input{'sender'} is a text form field that contains a person's real name, such as &quot;Jon Dough&quot;.


I made the suggested changes, and it works perfectly. As I said in the first post, I an a novice to PERL, and I just couldn't get it.

Thank you very much for the help.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top