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
https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/
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?

 

 

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";
     
    ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.