$SQL = "Select * from database where (TO_DAYS(enddate) - TO_DAYS(Now()) = 8) AND payment!='premium'"; &Do_SQL; $recordcount = $sth->rows; if ($recordcount > 0) { $sendEmails = 'yes'; } if ($sendEmails eq 'yes') { $count = 0; while ($pointer = $sth->fetchrow_hashref) { $contact = $pointer->{'contact'}; $toemail = $pointer->{'email'}; open (MAILPROG....."; SEND THE EMAIL HERE.... close (MAIL); print "email sent to: $contact <$toemail>\n"; $count++ } print "Sent $count emails.\n"; $action = "Email Reminders sent!"; $log = "Sent $count emails."; &log_it; #### Sent 4 emails.
Email sent to user1
Email sent to user2
Email sent to user3
Email sent to user4