cron to send 5 mails per minute

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

cron to send 5 mails per minute

Post by kkonline »

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?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: cron to send 5 mails per minute

Post by onion2k »

When the mail is sent have another query update the value of 'invitation' to something other than 0.
helraizer
Forum Commoner
Posts: 31
Joined: Thu Jun 05, 2008 8:20 pm

Re: cron to send 5 mails per minute

Post by helraizer »

Something like:

Code: Select all

 
 
$sql = "SELECT * FROM invites WHERE `invitation` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5"
 
$result = mysql_query($sql) or die("Error in sql: ".mysql_error());
 
$count = mysql_num_rows($result);
 
if($count == 5) { // all five were selected
 
$sqla = "UPDATE `invites` SET `invitation` = 1 WHERE `invitation` = 0 AND `email` LIKE '%@gmail.com%' OR `email` LIKE '%@yahoo.%' LIMIT 0,5"; 
 
$resulta = mysql_query($sqla) or die("Error in sqla: ".mysql_error());
 
} else {
 
die("error");
}
 
That basically says, if it selects the first 5 successfully based on your query the it updates the invitation field to Yes or 1. This means that they won't be selected again; it will then go onto the second set of 5 and do the same, etc.

Sam
kkonline
Forum Contributor
Posts: 251
Joined: Thu Aug 16, 2007 12:54 am

Re: cron to send 5 mails per minute

Post by kkonline »

onion2k wrote:When the mail is sent have another query update the value of 'invitation' to something other than 0.
I am doing the same thing with invitation = 0 after the mail is sent the invitation is made 1
but when i write the query and limit it to 0,5 it selects the same emails again and again
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: cron to send 5 mails per minute

Post by onion2k »

kkonline wrote:
onion2k wrote:When the mail is sent have another query update the value of 'invitation' to something other than 0.
I am doing the same thing with invitation = 0 after the mail is sent the invitation is made 1
but when i write the query and limit it to 0,5 it selects the same emails again and again
Ah.. it's your SQL..

If we rewrite it slightly..

Code: Select all

SELECT * 
FROM invites 
WHERE 1 
AND `invitation` = 0 
AND `email` LIKE '%@gmail.com%' 
OR `email` LIKE '%@yahoo.%' 
LIMIT 0,5
 
Each part of the where clause is separate. So it's selecting everything where invitation is 0 and email is like gmail, or where email is like yahoo... the invitation bit isn't applied if the email is yahoo. You need some brackets...

Code: Select all

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