Jump to content

Recommended Posts

If i've got a database of users that have filled out a form, can I use a cron job to send an automated email? If so, what is the best way to "loop" it so that it sends the email once to each user?

 $data = mysql_query("
 SELECT *
 FROM completed
 WHERE
 followupsent='0000-00-00 00:00:00'
 AND valuesent + INTERVAL 4 DAY <= NOW()
 ")
 or die(mysql_error()); 
 
 while($info = mysql_fetch_array( $data )) 
{
}

This checks to see if "followupsent" has been updated already as it updates with NOW() when it sends and also checks to see how many days since the value was sent.

 

I'm worried that by putting the email sending information in the while tags is going to loop for each row and end up sending a ton of emails.

 

Would using

 if($info = mysql_fetch_array( $data )) 
{
}

Send out to the first in the database and then the CRON Job handle the rest by checking every minute which one is next?

 

Cheers

Link to comment
https://forums.phpfreaks.com/topic/295146-cron-job-send-email-to-users-in-db/
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.