Jump to content

Cron and send mail


everisk

Recommended Posts

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!

Link to comment
Share on other sites

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>";

}

?>

Link to comment
Share on other sites

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.

}

?>

Link to comment
Share on other sites

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?!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.