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?

Recommended Answers

All 3 Replies

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

?>
commented: useful post +6

lovely cheers

lovely cheers

Mark this thread as solved if your problem solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.