1

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");
}?>
Sugs
  • 65
  • 1
  • 12
  • 1
    possible duplicate of [how to send emails automatically on certain day or time in php?](http://stackoverflow.com/questions/21777142/how-to-send-emails-automatically-on-certain-day-or-time-in-php) – Vidya Sagar Jul 01 '15 at 08:05
  • Create a function that will check for sending time and call that function by using cron. – Priye Ranjan Jul 01 '15 at 09:43
  • Can u add a column to csv or is that taboo in your setup? – Drew Jul 01 '15 at 15:01
  • Also what is wrong with @Martin 's notion you gave no feedback to him and asked me to take a look. Is it that you are on windows? This is a nice task for cron – Drew Jul 01 '15 at 15:23
  • This is regarding sending email. But I requested you to take a look at my coding since this is my coding & the issue with my coding was displaying all the rows' elapsed time in each row instead of display the elapsed time in respective row. (http://stackoverflow.com/questions/31117682/subtract-fetched-datetime-from-current-date-time/31118117?noredirect=1#comment50334094_31118117 ) Its not working though I add a loop. Hope you can help me on that. Thanks in advance! – Sugs Jul 03 '15 at 05:19

1 Answers1

0

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

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

Martin
  • 22,212
  • 11
  • 70
  • 132
Insane Skull
  • 9,220
  • 9
  • 44
  • 63