everisk Posted March 20, 2009 Share Posted March 20, 2009 Hi, I have a script that send a lot of emails from database and cron to make sure that it continues to send even after the script time out or stop running for some reason. However, how do I make sure that the email will not get sent twice? I think it is possible that the script is still running and when cron kicks in the same email might be fetch from database and that person will get the email message twice? Although I might delete the email address after it has been sent to but I think it is still possible that before it was successfully sent to, the cron kicks in and fetch the same email because the sending hasn't finished and therefore the email address hasn't been deleted. I'm still at the concept part so any thoughts would be greatly aprreciated. Thanks! Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 got it lol so the email that are sent need to be put in a session array then cheeked against the cron emails. <?php $testing=array("email2@u.com","email3.com");// incoming emails from a session[] array. $test=array("email1@u.com","email2@u.com","email3@u.com");// emails being re sent via cron //foreach the new emails the cron sending. foreach($test as $sent_email){ // cheek if there a match with the session[] array. if(in_array($sent_email,$testing)){ break; // stop those matched emails. } echo "$sent_email<br>"; // echo unmatched emails. } ?> <?php $ready_sent_emails=array("email1@u.com","email2@u.com","email3@u.com"); foreach($ready_sent_emails as $sent_you){ $_SESSION['emails'][]=$sent_you; } // let be tend, the emails are sent above, via the emai function. $testing[]=$_SESSION['emails'][0]; print_r($testing); $test=array("email1@u.com","email2@u.com","email3@u.com"); foreach($test as $sent_email){ if(in_array($sent_email,$testing)){ break; } echo "$sent_email<br>"; } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted March 20, 2009 Share Posted March 20, 2009 sorry re wrote the code as your see it works. <?php session_start(); $ready_sent_emails=array("email2@u.com","email3@u.com"); foreach($ready_sent_emails as $sent_you){ $_SESSION['emails'][]=$sent_you; } // let be tend, the emails are sent above, via the emai function. $testing=$_SESSION['emails']; //database sending all emails again via cron. $test=array("email1@u.com","email2@u.com","email3@u.com"); foreach($test as $sent_email){ if(in_array($sent_email,$testing)){ break; } echo "$sent_email<br>"; // this can now send the email that has not been sent yet. } ?> Quote Link to comment Share on other sites More sharing options...
everisk Posted March 20, 2009 Author Share Posted March 20, 2009 Thank you for your reply! A few questions, though. How could the session be available to another instance of the script? I thought session is tie with session id and i think if i run the script in cron, new session id is being created. And suppose I send 100K of emails the session variable will get soo big?! Quote Link to comment Share on other sites More sharing options...
everisk Posted March 20, 2009 Author Share Posted March 20, 2009 Any other idea would be appreciated! Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.