0

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

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?

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by karthik_ppts
1

Check this code.

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

?>
Votes + Comments
useful post
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.