How to refresh only a part of the script
Posted: Wed Aug 29, 2007 5:05 am
Hello All,
I have written a script that sends a mail to the administrator of the website at the end of the day. To do this i am checking whether system time is equal to the set time (this is the time at which i want to send the mail to the admin), and if the condition satisfies, i am sending the mail.
But i am stuck with this. To send a mail, it should check each time whether the system time equals set time or not, if it equals send a mail or else do not send a mail to the admin. For this, each time the page needs to be refreshed.
But if i refresh it each time, the index.php of the site also gets refreshed as the mailing script is contained in it. I do not want that to happen as this should not be known to the user. (hidden from the user).
So, can anyone help me out with this?
Here's my code
Regards,
Dream2rule
I have written a script that sends a mail to the administrator of the website at the end of the day. To do this i am checking whether system time is equal to the set time (this is the time at which i want to send the mail to the admin), and if the condition satisfies, i am sending the mail.
But i am stuck with this. To send a mail, it should check each time whether the system time equals set time or not, if it equals send a mail or else do not send a mail to the admin. For this, each time the page needs to be refreshed.
But if i refresh it each time, the index.php of the site also gets refreshed as the mailing script is contained in it. I do not want that to happen as this should not be known to the user. (hidden from the user).
So, can anyone help me out with this?
Here's my code
Code: Select all
<?php
ob_start();
//header("refresh:01;");
require "Mail.php";
// get the current timestamp into an array
$timestamp = time();
//echo strftime('%H:%M %A %d %b',$timestamp)."<br>";
$date_time_array = getdate($timestamp);
$hours = $date_time_array['hours'];
$minutes = $date_time_array['minutes'];
$seconds = $date_time_array['seconds'];
$month = $date_time_array['mon'];
$day = $date_time_array['mday'];
$year = $date_time_array['year'];
// use mktime to recreate the unix timestamp
// adding 5 hours to $hours and 30 minutes to $minutes
$systimestamp = mktime($hours + 5,$minutes+30,$seconds,$month,$day,$year);
$systime=date("h:i:s A",$systimestamp);
echo "SYS TIME - ".$systime."<br>";
echo strftime('%H:%M %A %d %b',$timestamp)."<br>";
$settimestamp=mktime(13,32,0,date("m"),date("d"),date("Y"));
$settime=date("h:i:s A",$settimestamp);
echo "SET TIME - ".$settime."<br>";
//REFRESH HERE EACH SECOND TO CHECK WHETHER THE SYSTEM TIME EQUALS SET TIME
if($systime==$settime)
{
//echo $systime."<br>";
//echo $settime;
$from = "Admin <some_name@some_site.com>";
$to = "Admin <some_name@some_site.com>";
$subject = "Test Mail";
$body = "Hi,\n\nHow are you?";
$host = ""; //smtp host address
$username = "some_name@somesite.com";
$password = "password";
$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);
$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail))
{
echo("<p>" . $mail->getMessage() . "</p>");
}
else
{
echo("<p>Message successfully sent!</p>");
}
}
?>Regards,
Dream2rule