Jump to content

php to send email every 10 mins


vlowe

Recommended Posts

Im still trying to work this one out but what i would like to do is send an email if an alert is present. but not resend the email on every page refresh where the alert is still present.

 

so i was thinking of using something like $_SESSION['sent_time'] to record when the last email was sent and only send another email if the current time is greater than 10 mins from the $_SESSION['sent_time'].

 

How can i record the time into the session variable in a format which i can use to compare with the current time?

and how will i compare?

 

cheers for any suggestions

Link to comment
Share on other sites

the email will only be sent while an alert exists.

 

so if i did something like

if((SENDEMAIL == "TRUE") && ($ALERT)) {
send_email();
} 

 

that will send an email if SENDEMAIL is set to true and an alert is present.

 

so i will then need to record the time the email was sent

$_SESSION['sent_time'] = date('h:i:s');

 

and add to IF somehow to check?

if((SENDEMAIL == "TRUE") && ($ALERT) && ($_SESSION['sent_time'] > 10 minutes ago!)) {
send_email();
} 

LOL how can i check if $_SESSION['sent_time'] is greater than 10 mins ago?

 

 

Link to comment
Share on other sites

i think i have it

    <? session_start();
    $sendAfter = (10)*(60); // in seconds
    $sendEmail = false;
    $now = date('Y-m-d H:i:s');
     
    if(!isset($_SESSION['sent_time'])) // if you are first time send email
    {
    $sendMail = true;
    $_SESSION['sent_time'] = $now;
    }
    else
    {
    $diff = strtotime($now) - strtotime($_SESSION['sent_time']);
    if($diff >= $sendAfter)// if difference is more than 10 min then only send mail
    {
    $sendMail = true;
    $_SESSION['sent_time'] = $now;
    }
    }
     
    if($sendMail)
    echo "mail sending code here";
    else
    echo "nothing to do";
     
    ?>

Link to comment
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.