简体   繁体   中英

How to send emails when elapsed time reaches specific hours automatically?

I want to send emails automatically to a particular group (outlook) when my elapsed time (in database) reaches 3 hours, 6 hours & 12 hours. I searched a lot, but i couldn't find an answer. Below is my coding to display the elapsed time so far. I prefer doing it in code than cron job.. Hope you all can help!.

Thanks in advance!!

<?php
$i = 1;
while ($csv=mysqli_fetch_assoc($records)){
$A=$csv['Name'];
$B=$csv['SRNumber'];
$C=$csv['ServiceImpact'];
$D=$csv['CustomerRefNo'];
$E=$csv['ReportedDateAndTime'];
$K=['ElapsedTime'];
?>

<tr>
<td><?php echo $A; ?></td>
<td><?php echo $B; ?></td>
<td><?php echo $C; ?></td>
<td><?php echo $D; ?></td>
<td><?php echo $E; ?></td>
<td><?php echo $K; ?></td>

<td><?php
date_default_timezone_set('Asia/Colombo');
$the_time = date('H:i');
$sql="SELECT ReportedDateAndTime FROM csv";
$result=$conn->query($sql);
while ($row = $result->fetch_assoc()){ 
$new_time=$row['ReportedDateAndTime'];
$datetime1 = new DateTime($the_time);
$datetime2 = new DateTime($new_time);
$interval = $datetime2->diff($datetime1);
$hours=$interval->format('%h');
$minutes= $interval->format('%i');
$seconds= $interval->format('%s');
echo $hours." Hours  ".$minutes."  Minutes ".$seconds." Seconnds</br></br>";
} ?>
</td>
<td>
<a href="Escalation_Display.php?delete=<?php echo $B?>" onclick="return confirm('SR Resolved?');">Archive</a>
</td>
</tr>

<?php
$i++;}
if(isset($_GET['delete'])){
$delete_id = $_GET['delete'];
mysqli_query($conn, "DELETE FROM csv WHERE SRNumber = '$delete_id'");
header("location:Escalation_Display.php");
}?>

Better you schedule email using cron job. This is probably the best way for sending emails.

http://docs.phplist.com/CronJobExamples.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM