My system is for reservations, and I want to send a reminder email 15 minutes before without using cron on Linux/Unix/BSD boxen nor Scheduled Tasks on Windows because I'm using mac and the users' PCs will be windows.
So, what should I do?
Initially, I compared all date and time with the ones in the data base but still nothing arrived.
Thanks in advance.
I tried if the date&time now = the date&time in the DB send a conformation email.
and about the corn I have 2 things:
1- I'm using mac -as a programmer- and if I want to implement this function I'll have to use Scheduled Tasks on Windows which - as I think- will be need working on a windows environment.
and the system will be installed on a Microsoft PC.
2- I have not dealt with corns before, and I'm afraid it'll take time that I don't have.
You have to use some kind of service or job to trigger the email to be send. Because php is self needs to know when to exec the code ("script").
Use CRON or Task Scheduler or build your own job / Service
For Scheduling jobs on linux you can you at command. Here is example
at 12:32 -m -f /usr/local/bin/backup-script
Here is good manual for at linux.
http://www.brunolinux.com/02-The_Terminal/The_at_Command.html
If you want to avoid cron job, then you have to depend on some hacky solution to trigger/call your "send email" code
like,
depend on site users. If they are coming on regular intervals every minute, check on each reservation the upcoming reservation time and email to them.
run a daemon process OR a function that keeps running for a specific period of time, say 24 hours, and check for upcoming reservations every minute or xyz time. You can put this process on sleep for a minute (or more) to check reservations on regular intervals.
use 3rd party cronjob scripts or hosted cronjobs. like https://www.setcronjob.com/ (needs $ for this solution) or onlinecrontab.com
Related
Is there a way where I can automatically call a php script after a specified interval.
I have a php script(say remindusers.php) that uses mysql to query a database where people have submitted their weekly reports. This script automatically queries the database and sends an email reminder to people who have not sent in their weekly reports yet.
What I am now supposed to do is give the ADMIN an option to set a reminder start and reminder end date during which calls should be automatically made to my remindusers.php script and cease on reminder end date.
What I learnt from SO/google is that I can setup cron (in LINUX) to automatically call my remindusers.php, but I dont have any shell access to do this.
Else Can I write another php script to essentially sleep every 24 hours and automatically wake up to call my remindusers.php script.
Are there any other built-in methods ?
Any ideas?
Use your site's visitors to trigger the event. Send a message and then check if 1 day elapsed. Then send another. You still need to pay attention not to double/triple/... send deu to synchronization.
When the time has elapsed use a MySQL (or system) MUTEX to ensure only one send occurs.
Yes you can! What you need to do is to use cron jobs. Cron jobs are essentially telling the server to execute a script (PHP or otherwise) at regular intervals. Cron jobs are very powerful and customizable, as you can set virtually any interval for your cron.
If you are using CPanel to manage your site, there is a button in CPanel to view all the cron jobs you have set. There is also a tutorial on that page.
Hope this helps.
Try with this PHPCron
PHPCron is a simple PHP script which lets you run multiple tasks on a schedule or timer. It can be run either from the command-line or via a web browser. Its behaviour is very similar to the popular cron program for UNIX.
http://katyscode.wordpress.com/2006/10/17/phpcron-running-scheduled-tasks-from-php-on-a-web-server/
I understand that you don't have Shell access but have you had a look at the cPanel to see whether there is an option to setup a cron job in there?
I am having some mail ids in my database. I have to send mail to those mail ids automatically on some specific dates that i have mentioned in my database.How to do that in php.
It depends on your server type. If you use linux you can use cronjobs to program the execution of a specific php file at a certain time.
If you are hosted, your host may offer a cronjob menu in their cpanel, else you would have to get a better hosting plan that offer that. Or at least access to crontab file where you program the different Cronjobs.
Executing a PHP script with a CRON Job
You need to write cron jobs for sending the automatic emails on a particular date. Without this it is not possible.
Syntax
Here is a simple cron job:
10 * * * * /usr/bin/php /www/virtual/username/cron.php > /dev/null 2>&1
There are two main parts:
The first part is "10 * * * *". This is where we schedule the timer.
The rest of the line is the command as it would run from the command line.
The command itself in this example has three parts:
"/usr/bin/php". PHP scripts usually are not executable by themselves. Therefore we need to run it through the PHP parser.
"/www/virtual/username/cron.php". This is just the path to the script.
"> /dev/null 2>&1". This part is handling the output of the script.
Timing Syntax
This is the first part of the cron job string, as mentioned above. It determines how often and when the cron job is going to run.
It consists of five parts:
minute
hour
day of month
month
day of week
Or
You can set the cron in you cpanel.
Here are a few general steps of the logic that you can follow:
The PHP script should:
extract the email addresses and the specific dates from your database
into arrays.
check whether
today's date is
in the array containing the dates. Be sure to format the date appropriately!
loop through the email addresses (preferably in a foreach() loop),
if the above check returns 'true'.
within this loop, use PHP's mail() function to send your email.
Your next step would be to set up a scheduled task that runs this script daily, usually by means of a cron job. This step depends on the server you've got.
NOTE: These steps illustrate the most basic way to do what you require. There may be other, more complex ways that would be faster, cleaner and less intensive on your server.
As answered by Albert James it depends on the system type on which your application is running. If it is Linux then you can get the php script which send mail executed by cron jobs and if you are using windows machine then you need to execute that php script with schedule task : How to run a PHP file in a scheduled task (Windows Task Scheduler)
Also here is the option if you don't want to use schedule task\cron jobs (Though I haven't used that): How to send schedule emails using php without cron job
The software utility Cron is a time-based job scheduler in Unix-like computer operating systems. People who set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals.
example
I am using a shared windows hosting in which sending 120 mails/hour is allowed though php code.
i have a php page to send emails more than 200 mails at a time.But i want to run the page, after every hour(scheduled task).
I will split the emails(in 100s) and want send automatically after every hour.
How is this possible in php to run a php page after every hour ?
Thanks
Use PHP Cron Jobs with cPanel
cPanel Simple Cron
you can get started with the simple cron tool built into cPanel. The url for it is:
https://www.yoursite.com/page.php
The command to run:
/usr/local/bin/php -f /home/(username)/public_html/page.php
Next you'll want to select an option from all the select boxes. Remember to select an option in each box. If you want something to run every hour, select Minute: 60; Hour:Every; Day: Every; Month: Every; Weekday: Every;
Click save and you are all set! You'll get an email every time the cron job runs, but if you don't want to get it - put :blackhole: into the output email field at the top.
Use a script on Google AppEngine to "ping" yours (Scheduled Tasks to be more precise).
It's free to use.
You can schedule a task in Windows - control panel->administrative tools is where you find task scheduler.
i managed to send multiple emails (check here).i am stuck with sending automated emails via cron.
This is what i need - while the admin send emails, i store the message, emails, event date in the database. now i am trying to set a cron job to send emails to all these ids from the table with the message i have as a reminder. i am not familiar with cron job scripting, can anyone help in guiding me the right way to write script that i can place in cron tab. I am planning to send two mails - one day exactly before the event and on the day of event.thanks
Just write a normal PHP script -- make one that will work if it's launched directly from the browser. Then schedule that very same PHP file to run in cron, using this as a guide:
http://www.unixgeeks.org/security/newbie/unix/cron-1.html
Basically, using the values at the beginning, specify the schedule (minute, hour, day of week, day of month, etc.). Then set the user it runs as, which is likely to be "apache" or whatever your web server daemon is running under. Then set the "command" that cron is running to be php php_email_script.php (where "php_email_script.php" is the name of your PHP file.
30 minutes and still no answer, here's a few open doors:
cron reads it's rules from system-wide /etc/crontab, or from you personal crontab which you edit with crontab -e
cron takes a format where you say on which minute / hour / day / month things should happen, use google or man crontab for the format
cron has the amazing side effect of mailing the output of the command to the user owning the crontab
Now you are stating that you're using php. The easiest way to get some php running from cron, is to issue a wget -O - -q http://yoursite.com/yourprocessingscript.php?verysecret=123123 and have an appropriate processing script on yoursite.com. (you may want to let that script check $_SERVER['REMOTE_ADDR'])
So in short, if you just put the right magic in /etc/crontab, like
0 0 * * * jay wget -q -O - "http://yoursite.com/processmidnight.php?secret=yes_very"
and have your script produce some sensible output, you will get a mail delivered to local user jay, which you may want to forward.
I want to a e-cards or something like that. The user can choose the e-cards, after chosen, he must enter the some fields like name(to and from), email(to and from), message and I want to let user to choose which date to send the e-cards.
How to send the e-cards on specific day? I need to write a script that run every new day? How to do that? Sorry, I am new to php... (but not beginner like not even know how to execute mysql query, get message from url etc)
Yes, you need a script that runs every day. (Barring ridiculous maneuvers like trying to fake this by checking on Web requests.) The usual way to do this in a Unix context is called a cron job; if your hosting provider is Unix-based, you should look into what they provide for making cron jobs available to you. On Windows there's a parallel service called Scheduled Tasks.
A similar question was disscussed here resetting-a-mysql-field-value-without-user-execution
I'll just reiterate: There are web based cron services too. This could come in handy if you only got a shared hosting plan and can't add cron jobs. They will call an URL at a regular interval that you can set. Usually very cheap. (Cheaper than upgrading to a root-access server anyway.)
Just search Google for web based cron
ciao!
/0
This is for *nix.
Let's say you have a php script that sends email on a specific day called mailer.php
<?php
//mailer.php
if (date("m/d/Y") == "06/02/2009") {
mail("client#email", "Subject", "Body");
}
?>
We are going to assume that you already have cron daemon running in the background.
If you have root access to your machine, then setting up a cron job is simple as editing a file.
Open up /etc/crontab file and add the following task:
1 14 * * * root php /path/to/your/scrip/mailer.php
This means, as a root, the mailer.php script will be running daily at 02:01PM. You can change the numbers to whatever you desire.
This is somehow complex. First it depends on your system. If it is Linux/BSD/Unix/Solaris then you have this handy utility as cron. If you are using Windows, you have Scheduled Tasks. Run your script daily (or as you wish) and check what cards you have to send today.