Palm Optins wrote: > Hello All. > > I have a admin script for a protected members area. In it, I can email all the > members > to let them know the Updates of the program. > > For some unknown reason, it keeps sending out double emails for each address. > Can someone tell me what I did wrong? > > Here's the code I used for the mailer:
Hi Linda, I'm a little mystified that this compiles at all. After adjusting the indentation and doing my best to match visible braces, I found two missing closing braces in mmail(), at the end of the else block for if ($pid), and at the end of the sub itself. I noticed that you are not using strict. I would suggest that until you can get used to writing under strict compilation, you hold off on things like fork(). I can't really see that it serves any prupose here but to lend confusion. I am posting a reformatted version of your code here. Please let us know if this is the correct interpretation of your intent. sub mmail { $pid = fork(); # DONT do this! use strict; and declare your # variables with scope qualifiers my or our print "Content-type: text/html \n\n fork failed: $!" unless defined $pid; if ($pid) { &mailsent; exit(0); } else { close (STDOUT); ##### SEND OUT EMAILS HERE ############ open (DAT,"<$memberinfo/amdata.db"); if ($LOCK_EX){ flock(DAT, $LOCK_EX); #Locks the file } @database_array = <DAT>; close (DAT); foreach $lines(@database_array) { @edit_array = split(/\:/,$lines); open (MAIL, "|$mailprog -t") || print "Can't start mail program"; print MAIL "To: $edit_array[2]\n"; print MAIL "From: $orgmail ($orgname)\n"; print MAIL "Subject: $INPUT{'mail_subject'}\n"; print MAIL "Important Admin Message Below\n"; print MAIL "-" x 75 . "\n\n"; print MAIL "$INPUT{'message'}\n\n"; print MAIL "======================================\n"; print MAIL "Admin:\n\n"; print MAIL "$orgname\n"; print MAIL "Email: $orgmail\n"; print MAIL "======================================\n"; close (MAIL); } # no closing brace seen for if ($pid) else block # no closing brace seen for sub nmail() ----------------------------------------------------- sub mailsent { print "Content-type: text/html\n\n"; header(); # call subs explicitly # If you are going to use heredocs, use them well # Make HTML source also understandable through clear # block-level indentation print<<EOF; <FORM ACTION="$cgiurl" METHOD="POST"> <CENTER><BR> <TABLE BORDER="0" WIDTH="500"> <TBODY><COLDEFS><COLDEF></COLDEFS><ROWS> <TR> <TD COLSTART="1"><P><B><FONT FACE="verdana, arial, helvetica"> <FONT COLOR="#FF0000"> Account Manager</FONT> Status: Success!</FONT></B></P> <P><FONT SIZE="-1" FACE="verdana, arial, helvetica"> Mass Mailing has been sent!</FONT></P> <P><FONT SIZE="-1" FACE="verdana, arial, helvetica"> Please contact <A HREF="mailto:$orgmail">$orgname Support</A> if you need any further assistance.</FONT> <BR><BR></P> </TD> </TR> </ROWS> </TBODY> </TABLE> </CENTER> <HR SIZE="1" WIDTH="450"> <CENTER> <TABLE BORDER="1" WIDTH="500"><TBODY><COLDEFS><COLDEF> <COLDEF></COLDEFS><ROWS> <TR> <TD VALIGN="MIDDLE" ALIGN="CENTER" WIDTH="50%" BGCOLOR="#C0C0C0" COLSTART="1"> <INPUT TYPE="SUBMIT" VALUE="Main Menu Return" NAME="admin2"> </TD> <TD VALIGN="MIDDLE" ALIGN="CENTER" WIDTH="50%" BGCOLOR="#C0C0C0" COLSTART="2"> <FONT SIZE="+1" FACE="verdana, arial, helvetica"> <B><FONT SIZE="-1">Main Menu Return</FONT></B></FONT> </TD> </TR></ROWS> </TBODY> </TABLE> </CENTER> <CENTER> <TABLE BORDER="0" WIDTH="500"> <TBODY><COLDEFS><COLDEF></COLDEFS><ROWS> <TR> <TD COLSTART="1"> <HR SIZE="1"> <CENTER> <FONT SIZE="-2" FACE="verdana, arial, helvetica"><B> $orgname © $copy</A></B></FONT> </CENTER> </TD> </TR></ROWS> </TBODY> </TABLE> </CENTER> </FORM> EOF footer(); exit; } My advice is to discipline yourself on more modest projects, get used to strict compilation and logcal indentation conventions, and then move on to more complex procedures. Save fork() projects until you have a very clear understanding of process flow within a single thread. Joseph. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]