Forum Moderators: coopster

Message Too Old, No Replies

cron to send 5 mails per minute

         

kkonline

8:06 am on Jun 18, 2008 (gmt 0)

10+ Year Member



Hi,
I want to use cron tab to send 5 mails per minute(the time part can be adjusted using cron that's not the issue)
but when i write the query as:

PHP Code:

SELECT * FROM invites WHERE `invitation` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5

it always selects the same first 5 emails.
basically i want after every cron run the next 5 emails should be sent mail. How to adjust this using the above query?

Br3nn4n

9:00 am on Jun 18, 2008 (gmt 0)

10+ Year Member



First thing that pops into my mind is _adding_ a field, named maybe "been_emailed" (minus the quotes, obviously)

Then, when the email is sent, for those 5 emails it selects, have it update each row and set those 5 to "1" for the "been_emailed" field.

Instead of the query you had, run this:

SELECT * FROM invites WHERE `invitation` = 0 & `been_emailed` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5

Then, the 5 you just sent will not apply since their "been_emailed" field has a value of "1" instead of "0".

Let me know if that works :)

kkonline

9:51 am on Jun 18, 2008 (gmt 0)

10+ Year Member



Hi dear,
I have the invitation field set to 1 after every mail is sent, HOWEVER with the query limit 0,5 it gives me the same email addresses

dublinmike

10:23 am on Jun 18, 2008 (gmt 0)

10+ Year Member



You can use ...LIMIT 5,5 to offset the results that you pull down. So, LIMIT 0,5 would bring back the first five, LIMIT 5,5 the second five, LIMIT 10,5 the third five &c. You will need to keep track of the offset though. I would just store it in a textfile on your server e.g.


$offset = file_get_contents("my_offset.txt");

Then write the new offset into the file. You can check when you've reached the end of your items by interrogating the number of returned rows, e.g.


if(mysql_num_rows($result)!=5)
{
// Write out offset '0' into
// my_offset.txt to start again or
// mail me and tell me to shut off the
// cron...
}

There's a million ways to keep track of the offset, that's just one. With regard to your current solution, I would make a guess that you have an error in the query that is setting the 'invitation' field to 1 after the mail is sent - that's why you're getting the same results. Hope this helps anyway.

Br3nn4n

4:00 am on Jun 19, 2008 (gmt 0)

10+ Year Member



@kk-That's how I run my comments system and it works.....hmmm.....I think dublinmike is right about your query being wrong to set the invitation to 1 for the ones that have been emailed. Otherwise it should work..

sorry I didn't see you had already done what I suggested haha.