How to change the contents of a variable every 30 minutes

Asked

Viewed 49 times

-1

The code below causes the e-mail to be sent specifically to a particular e-mail specified in the variable $email_remetente and basically if the time is greater than specified in the function: $dates->setTime(13,30,00); it sends to another email.

The idea would be that every 30 minutes he changed the variable $email_remetente to an email and after 30 minutes back to another email.

<?php

 header('Content-Type: text/html; charset=utf-8');

  date_default_timezone_set('America/Sao_Paulo');
$date = date('Y-m-d H:i');

$email_remetente = "[email protected]"; 

 //altera email do remetente de acordo com a hora

 $dates = new \DateTime();

$dates->setTime(13,30,00);

$dateNows = new \DateTime();



if($dateNows > $dates) {
    $email_remetente = '[email protected]';
}

?>
  • "if time is greater than specified in function" ... an IF does not resolve !?

1 answer

2


Good night. I don’t know if I understand this very well, but I believe that you want to implement a kind of shift for the support emails, so every 30 minutes, it’s the other one that goes into action. If that’s right, there are several ways to do that. If there are only two emails, you will send it to the first one whenever the minutes are less than 30 and to the other one whenever they are larger or equal. Then implementing:

<?php
$minuto = (int) date('i');
$email = ($minuto < 30) ? "[email protected]" : "[email protected]";
// ...

So the emails will be:

  • 10h29 Email1
  • 10:30 Email2
  • 10h55 Email2
  • 11h00 Email1
  • ...

If you want to do it dynamically, you can set an array with the start time for each email and scroll through it to choose the nearest one.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.