1

im trying to build my own autoresponder.

I have a database of users where their emails and signup dates are stored...

Now I want to send each user every day one email for x amount of days. I thought it might be a good idea to setup a cronjob to do that.

But now here the problem...

How do I setup my script to check EACH USER if an email should be send today i.e. if he already got one today or signed up today?

Do you guys have an idea?

2
  • 1
    Keep a table where you put in the auto_responder_id and user_id if it has been sent to the user. Do a left join on this table and make sure that it's NULL.
    – h2ooooooo
    Dec 4, 2013 at 11:33
  • can you explain your idea a little bit more? i honestly have no idea what you are talking about :) Dec 4, 2013 at 11:37

1 Answer 1

0

Do you need to check if the user has already been sent an email? If the cron job runs to send emails to users, then it will run at the same time every day just once. So they will only ever receive on email.

So, just send a user an email when they have finished signing up, then send an email to all other users at the same time every day, so long as they didnt sign up today.

$user = array('username'=>'jackalopezero', 'created'=>'2013-12-04')l
$now = date('Y-m-d');

if($user['created'] != $now){
    //send email
}

Alternatively, if you were determined that ALL users should receive an email every day (even the new ones), then you could include a "last received " field and chnage it every time they have receive an email.

$user = array('username'=>'jackalopezero', 'last_sent'=>'2013-12-04')l
$now = date('Y-m-d');

if($user['last_sent'] < $now){
    //send email
    $user['last_sent'] = $now;
    //update user in DB
}
1
  • thanks man! running the cronjon once a day is what i needed. didnt thought about that. i firstthought about running it every minute and then compare the registered day with the current date but this is easier! Dec 4, 2013 at 11:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.