Jump to content

Send email at Specific Time ? Automatically


Zyphering

Recommended Posts

can you not use the if(); with a variable $time

and then set this using PHP time?

 

I can do that but that means I will need a computer to keep open the webpage and auto refresh it at a fixed intervels so the script gets called again and again till it meets the time constraints. ( I think) any other way to do this ?

 

you can use a cron to do that

 

 

I am not running PHP on a UNIX server and my knowledge of unix is very weak. Any other alternative ?

Link to comment
Share on other sites

If you have enough visitors on your website, you can use them as a 'cron' daemon!

 

Each time somebody loads a page, check if it's 07:00 and if it is, you can send the email. It's not guranteed to send at the right time, but if you get a lot of traffic, it would be pretty accurate.

 

But this is a last resort for people that don't have any type of cron system. Always use cron if you can.

Link to comment
Share on other sites

If you have enough visitors on your website, you can use them as a 'cron' daemon!

 

Each time somebody loads a page, check if it's 07:00 and if it is, you can send the email. It's not guranteed to send at the right time, but if you get a lot of traffic, it would be pretty accurate.

 

But this is a last resort for people that don't have any type of cron system. Always use cron if you can.

 

Hmm that is the problem. On my website 30 Employees will be working 8 hours a day from 8 A.M. to 5 P.M.

After 5 P.M. nobody will be even touching or logging into the website. So no traffic at all.

 

I guess I will have to ask a manager to manually send the end of the day report each day by logging in and clicking some button.

 

I don't think you can trigger a php script without user interaction. (is that the bottom line) ?

Link to comment
Share on other sites

Yeah, that's correct, Zyphering. >_>  Why aren't you hosting your site on a *nix system, if you don't mind my asking?

 

Well currently the Project is in testing phase.

And I created a small testing server for me on Windows XP (lol) with PHP, MYSQL, IIS.

 

After a few weeks of testing the project (on 4-5 users) it will move to the Server House.

To serve more users (around 30).

 

Then maintaining and keeping the server up won't me my problem.

They might use *nix if they feel like, totally depends on them.

 

My knowlege of *nix is weak, never got time to interact with it.

Link to comment
Share on other sites

If you want to stick with the system you have just create a page called RUN.php or something. Create a js onload function that is recursive on a timed interval of like 10 seconds. Within that page put the single script to check if time is the desired time and then if so send the email. You can leave this page open on any system anywhere and it will work. I work with large scale business software that is written in VB? and it does crap like this and they get paid bukoo bucks for it. So its like a service on the system you run it on. Its not to shabby if you have a server that is running all the time. Just open the page on it and leave it running.

 

Matter fact I think I will try this on a program I am writing now.

Link to comment
Share on other sites

If you want to stick with the system you have just create a page called RUN.php or something. Create a js onload function that is recursive on a timed interval of like 10 seconds. Within that page put the single script to check if time is the desired time and then if so send the email. You can leave this page open on any system anywhere and it will work. I work with large scale business software that is written in VB? and it does crap like this and they get paid bukoo bucks for it. So its like a service on the system you run it on. Its not to shabby if you have a server that is running all the time. Just open the page on it and leave it running.

 

Matter fact I think I will try this on a program I am writing now.

 

Yup that was what I told earlier.

Keepeing a page open and making it Auto-Refresh will solve the problem.

But then there are reliability issues if the page closes.

 

This code will help your program.

You won't need a recursive js onload function. (I think) Header refresh will take care of it.

Just code the function to check time and send email.

 

<?php
check_if_Time_is_Greater_And_Send_Email($timeToSendEmail);
header('Refresh: 5');
?>

 

 

if it is on a windows system you can use a scheduling program to automatically invoke ie to run the proper script at the appointed time

Nice Idea I can  use a windows scheduling agent to launch the webpage and it can check weather the time is greater then the Required time to send the report.

 

Cool never thought of it.

I will try this, if I get stuck I will message you.

Thanks a lot.

 

Link to comment
Share on other sites

I have a solution for you with this that will NOT require you to use a cron job (and probably not even an IF statement).

 

1.  Create a page with a really strange name that no one could ever guess and never ever tell anyone that page name.  For example.

 

end_of_day_report_987654321asdfg.php

 

Then download a FREE alarm clock program for your home personal computer.  Something like this here...

http://mac.softpedia.com/get/Utilities/Alarm-Clock-Pro.shtml

 

That one is for a mac but you can find something anywhere by doing a google search.  Then trigger an alarm to go off on your computer every day (M-F) at 7pm and when the alarm goes off have it open up that particular page which will then generate report and e-mail it out.  Let me know your thoughts on this one.

Link to comment
Share on other sites

  • 5 years later...

Here's another way to have it loop through an array:

 

<?php
header('Refresh: 5');
 
$setup=array("2013:09:27 07:52:00 am", "2013:09:27 07:53:00 am");
 
$arrlength=count($setup);
 
$timeis=date('Y:m:d h:i:s a', time());
$timem=date('Y:m:d');
 
echo $timeis;
 
$timer=date('Y:m:d h:i:s a', time());
 
for($x=0;$x<$arrlength;$x++)
$mytimer=$setup[$x];
 
if ($timer>=$mytimer)
{
echo "<br><p>It works, email will now be sent.";
}
 
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.