Id like to generate an automatic email at certain times of the week or daily from my website to certain users. i.e at 12am, or 5pm .I'd like an email reminder sent to user example#example.com. Can anyone point me in the right direction. I have read about cronjob but didn't got much information.
You are looking in the right direction... A cronjob would suffice.
This would allow you to run a php script on a schedule
Start by looking here
Do you have shell access to your host? Or does the host have CPanel installed?
If you have shell access, you can run the following command:
crontab -e
Then insert a new line like this:
* 0,17 * * * /path/to/php/executable /path/to/script/which/sends/emails.php
This will call your PHP script every day at hours 0 and 17 (12AM and 5 PM). The email sending should be done in /path/to/script/which/sends/emails.php
You need to create php script which will do all work (get data to send, get emails list, send data). After that You need to assign this script to schedule in crontab
Related
I am trying to set up a system where a user enters some information in a form and an email will be constructed where the information is saved into mysql.
I am trying to figure out how to make it so the email will be sent, for example, 20 minutes after the user makes their input. (Without the user staying on the browser).
I need this delay as I need the ability for an admin to log on to a page to look at the email and possibly edit it before it sends.
Is this possible through a cron job. Am I able to set one up that automatically checks sql table for an update and then sends the email after a certain time?
Or is it possible to delay a php script with the sleep function and then send the email. Can I make the PHP script still run when user has closed site and left?
you can use mySQL to store the data sent by the user. this data will be accessed later using another script triggered by a cron Job: if you have the ability to set cron jobs in the control panel or via access to the server, go ahead, use cron tab syntax to define when the job will be triggered, this website may help you:
https://crontab-generator.org/
another approach is to use external service to trigger an event every interval, the event could be accessing the cron job script via HTTP.
if you want your email to be sent exactly after 20 mins, please add a field to your mysql table indicating the desired send date(beware of timezones).
you may also want to add a flag indicating if the email is sent, so you do not send the same email twice.
You can't (easily) have a PHP script stay alive that long.
Your best strategy, IMO, would be to have the PHP script create the email file, and notify the human.
Then you can have PHP run a shell script which uses the "at" program to schedule a task to happen in 20 minutes. At is a cousin of cron, but is better suited for this job.
That scheduled task will be to take the e-mail message, move it some place else (like a "done" directory), and pipe it through your mailer. tip: /usr/sbin/sendmail -t < myEmailFile will work on most Linux boxen.
I have one problem. I am learning cakephp 3 and I want to do the folowing:
User enters date and time (this is saved into mysql as datetime format) and system needs to send email few hours before this datetime that he enters (for example, 1 hour before)
However, I want to do this without cronjob.
So user enters 2019-05-12 12:00 and I want immediately to schedule task to send email on 2019-05-12 at 11:00.
Is this possible and yes, can you please give me any pointers? I also checked cakephp tasks, but it seems that I don’t see the whole picture yet
create Shell
bin/cake bake shell CronJobs
open created shell and create method to send email, for example:
public function sendEmal()
{
}
Inside this method add your code to select data and Mailer to send mail.
now in your cron tab set task and point to this shell script, example
* 1 * * * bin/cake CronJob sendEmail
Please read:
https://book.cakephp.org/3.0/en/console-and-shells/shells.html
https://book.cakephp.org/3.0/en/console-and-shells/cron-jobs.html
https://book.cakephp.org/3.0/en/core-libraries/email.html
Update:
However, I want to do this without cronjob.
Other way is to implement some Queue system.
Read here for more information
I have the php project for user can register and buy the hours to listen music or video, the not used of 50% hours have to rollover to next month, I wanted to automate this process when user complete one month I have to check their usage and process the rollover using php. I have following user details on DB, Signed-up date with time and usage and hours they purchased and used hours. I want to do it once in a month for each customer.
Is it possible using cron jobs? I don't have any idea to do this.
Not sure if this is the right approach but I've been running such kind of scripts when a user logs into his account.
For example.
You can do something like on successful login request by the user
if(date of buying hours has crossed the specified limit) /here you can check for expiry date/
{ // run your script here
}
else{}
just a suggestion!
You don't need to update all of the records all at once. Just update it for the user who logs in.
At the end, it will be updated for every user I think.
yes this possible with Cron Job 1st Create your php file with your condition use update query then add this cron job file in your server Cron Job Section and select date when you want to run this file. in cron job just file your cronjobfile.php name , Date and time when this file run.
Short answer: Use Cron job.
Syntax and usage of how to use it is almost straight forward. Here's a cheat sheet.
Note: If you're on a shared host, some hosts don't allow you to use cron job.
Edit: What #Havenard suggested is correct. The below cron job will visit the url once at minute 00 of every hour:
0 * * * * wget http://www.mywebsite.com/some/link
I need some help regarding the implementation of the following alarm.. Here's the flow of the program, user login to the system and then they can click the hyperlink create schedule and then from there they can create schedules using the form. After which, user can choose to start this schedules that they created and they can allocate a timeframe to it. For eg, if the user assign the schedule to run at 2pm the system will have a pop up to notify and inform the user to run this schedule probably 15 mins before 2pm..
I would like to know what are the ways to implement this in php and if possible is there any reference i can use on the website? I've tried to find but apparently most scripts are paid etc.
I think you are looking for scheduler kind of thing, to do this in php
you can use scheduler for windows os
cron job for *nix based os
Yes the answer to this question is pretty much related to CRON job. Take a look at this answer
Execute Query on a Specific Date and Time
You need to write a PHP script that scans the db and sees for the user who should be notified (i.e their deadline has arrived). Run this script in the scheduler (maybe every 1 hour) and it will do the magic for you. Good luck with your notifications :)
No cron job is needed if you only notify user with popup on the web site, however, you will need a cronjob if you want to send emails.
You will have to store users schedules (possibly in a db table)
When the user logs in php should check if there's a task due in the schedules table for that user: if yes show the pop up.
You will need to create an ajax call (with users id) that will call a certain php (say ajax.php) file every minute. You can help yourself with jquery.
The ajax.php should check if there was a task due in the past. If yes it returns job details (as json or html, you chose) else it just returns that there are no jobs.
When the calling ajax code recieves an answer from ajax.php, it does nothing if the answer is that there are no jobs or displays a popup with job details recieved from ajax.php.
The user can dismiss the call (delete it from the schedules db table) snooze or reschedule it (update the due date in the schedules db table).
Don't forget about security especially in the ajax.php: it has to check if the user is logged in.
Only if you want to prompt non logged in users by email you will need to set up a cron jobs, that will ping the ajax.php file periodically.
I have a PHP web site. In this all my users have an expiry date about 1 month ( if a user register today his expiry date will be 2nd of the next year).I need to automatically update the expiration date of my user's profile and send a mail to that users( even he is logged or not). But I don't know how this? I heard about the clone function (I am not sure is it clone or not) to implement this type of automatic function. If does anyone know this please help me...
Instead of clone I think you mean cron. You can set up a cron to run a php script that will do these updates for you. Just write the php script that will do the update. Then, in your unix shell:
crontab -e
Specify the minute/hour/dom/moy/dow that the cron should run and then php /path/to/update/script.php