vlowe Posted September 8, 2011 Share Posted September 8, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/ Share on other sites More sharing options...
JKG Posted September 8, 2011 Share Posted September 8, 2011 for how long? for ever? cron job? would put quite a strain on the server... Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/#findComment-1266779 Share on other sites More sharing options...
voip03 Posted September 8, 2011 Share Posted September 8, 2011 <?php echo 'Current time: '.date('h:i:s').'<br>'; //current time echo 'In 10 Minutes:'.date('h:i:s',strtotime('+10 minutes')); //future time ?> Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/#findComment-1266788 Share on other sites More sharing options...
skwap Posted September 8, 2011 Share Posted September 8, 2011 you can use cron job to do scheduled process. Just make a a page & write the code to send a email after set up a cron job command. Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/#findComment-1266796 Share on other sites More sharing options...
vlowe Posted September 8, 2011 Author Share Posted September 8, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/#findComment-1266804 Share on other sites More sharing options...
voip03 Posted September 8, 2011 Share Posted September 8, 2011 add this code when you send the mail 1st time $_SESSION['sent_time'] =date('h:i:s'); For checking $currentTime = date('h:i:s'); if( $currentTime > $_SESSION['sent_time'] ) { echo "'Send New mail'"; } else{echo "Wait for 10 minutes"; } Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/#findComment-1266808 Share on other sites More sharing options...
vlowe Posted September 8, 2011 Author Share Posted September 8, 2011 cheers voip03 but isnt currenttime always going to be > session sent time? i need to compare the time differance between current time and session sent time, then check if the differance is greater than 10 mins.. Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/#findComment-1266816 Share on other sites More sharing options...
vlowe Posted September 8, 2011 Author Share Posted September 8, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246697-php-to-send-email-every-10-mins/#findComment-1266818 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.