PHP - Send Email on Day+1

1.9k views Asked by At

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?

1

There are 1 answers

1
RonnyKnoxville On BEST ANSWER

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
}