I ask you how to create a quartz (cron) in with the framework of Codeigniter 2 (php), I need to send an email at 2:00 pm every day.
I await your kind support.
Regards,
To do so, you need to add a make a php file that will send email. Suppose your file name is send_email.php. Now test that file is working or not by executing php send_email.php in the directory of your file. If this file sends mail successfully, then you know that this command will send email every time you execute it.
Now, you need to add this command in your Operating System's cronjob list. If you are in Linux, then open your terminal and execute the command crontab -e. Then select edit option to edit your cronjob. Add following line at the bottom:
0 14 * * * php full_path_of_the_file/send_mail.php
The first 0 means zero minute. Second number 14 means 2PM then rest three starts are for all week, months and year. then our old php command to execute php file. Then path to our created php file. Here, only the file won't work. You need to provide full path of your php file that send mail.
Save the file and exit. Now, your operating system will send email every day at 2:00PM.
Related
have a php page called cronEmail in the web folder. It incudes the code to end an email to specific users on the website. I want it to open the page once a day and send the email. The page has only php and MySql code to read the recipients of the email.
I am trying to use Task scheduler in the control panel to run the page. I create a user defined script and in schedule I set the time to a certain time and to only run daily once a day.
In the rum command i have tried numerous ways to run it on the time but every time it just passes and does nothing. an example of what I put in for the script is
/web/cronEmail.php OR
chmod 755 /volume1/web/cronEmail.php
There are only two of a many can anyone point me in the right direction
Thanks a million
Seems like you want a cronjob, in the terminal open cron with:
crontab -e
then at the bottom of the file place this
0 4 * * * php /url/to/folder/cronEmail.php
Not sure if you found another solution, but this is what worked for me. If you put the following in the "Run Command" section, it should work:
php /volume1/web/cronEmail.php
You can also create an error log by doing the following:
php /volume1/web/cronEmail.php>> /volume1/web/errors.log 2>&1
If you don't use the php at the beginning, and open up the error.log file that is created, what you'll see is that the Task Scheduler doesn't seem to know that it's looking for PHP, and doesn't recognize the script.
I am working on an automatic monitoring system. I have made a .NET application which have MySQL database. For this I developed a normal ADMIN Panel where admin can log in and get necessary reports coming from various queries fired on the database. There is also a "summary Report" in the panel which is just the rough weekly summary. Now What I want is, I want this report (all text) to get sent automatically to some email "xxxxx#xxx.com" with a seven day period. I have used some PHP scripts previously to send email on submit button click. Like the one below.
<?php
if(isset($_POST['isPost']))
{
$header="From:".$_POST['customer_mail']."\r\nName:".$_POST['name']."\r\nCity:".$_PO ST['city'];
$subject = $_POST['title'];
$message="From:$_POST[customer_mail]\r\nName:$_POST[name]\r\nPhone:$_POST[city]\r\n \r\n\r\n\r\n".$_POST['details'];
$to = 'xxxxxxxxx#xxx.com';
$send_contact=mail($to,$subject,$message,$header);
if($send_contact)
{
echo "<h6 style='text-align:center;color:green'>Sent Successfully</h6>";
}
else
{
echo "<h6 style='color:red'>Error sending e-mail'</h6>";
}
}
?>
this is normal mail sending script which works fine. But for the above purpose I want, Can anyone help me to set this action periodically and automatically or point me in the right direction on how to do this. I have googled for such php script but no satisfied results.
~ Regards
You can do this with cronjobs.
A long running process which executes commands at given times / dates / intervals.
Depending on what system you are, there are different methods.
If you have the script on a webserver someone is running for you / Webhost service
Ask the system administrator to run the script with a cronjob. Or search for any help documentation if you can setup this yourself in any admin-panel. Ask your webhoster /system admin for more information.
If you have the script on your own local machine:
UNIX
Try reading about crontab on how to run the php script, or any script for that matter.
For example type crontab -e and add the line below in your crontab, the cronjob will run your script every hour:
00 * * * * /usr/local/bin/php /home/Low-pointer/myscript.php
Here is some more information if you want to play with the intervals
Windows
If you use Windows you can use scheduled tasks to run the php command.
For example add the following command to the scheduler: C:\wamp\bin\php\php.exe -f C:\wamp\www\my_script.php
You can also use web cron services (Google it) these are online services which run a page (for example on your webserver) on designated times. For free or paid.
You can use Cpanel to send schedule emails through the cronjob(if you are using it).
Once you open cpanel theere would be crontab system.
Add your current code to a file(xx.php) and add this command to crontab in cpanel ,
/usr/bin/php -q /home/public_html/xx.php
like everyone have already said you must use cronjob to make your task.
I assume you use a Linux OS as your production environment.
So you need:
1) A php endpoint ( eg. www.mywebsite.com/emailsend.php ) OR a CLI php script that when called send the email.
2) The correct crontab rule
Here below an example of a simple shell script ( mailsend.sh ) that call an endpoint using CURL and save an html file with an eventual response given by the webserver
#!/bin/bash
curl http://www.mywebsite.com/emailsend.php -o /path/to/my/mailsendreport/"$(date '+%Y-%m-%d-%H-%M-%S')".html
To add a scheduled task to cron
crontab -e
then add a rule like below
50 23 * * 6 sh /path/to/mailsend.sh
What "50 23 * * 6" means? It means that every sixth day of the week, in the 23th hour, in the minute 50 your sh script will be called, and then your web app and the email is sent.
Once I wrote a small doc about this you can see it here
Cheers
You're looking for "cron job".
Edit: Or since it sounds like you might be on Windows, "Scheduled Tasks"
I have searching about 2 hs about this theme of cron jobs and codeigniter, my problem is to set the command by cpanel to send newsletter every day I cant access to the controller and its function.
THe mail that I receive copy all the code of my index page..
I think I have to make some route at the index look the command line that I use:
php -q /home/xxx/public_html/index.php report send
Thanks for your time.
Try this .......If you want a particular program to run, say, once every day at 10.45 am, the time portion of the cron schedule should read like this
45 10 * * * wget http://server_path/application/controller/method
I need to run a script that queries my DB and outputs the results as a CSV file. I have the script working to produce the CSV I now just need to figure out how to schedule this task for 2am and email the output CSV to a list of email addresses using PHP.
Any help or ideas would be appreciated.
you edit your crontab and simply schedule what you want to happen
e.g.
$ crontab -e
to edit your crontab. Add an entry to run your script
MAILTO=me#example.com
00 02 * * * cd /here && runMy2AMScript
And that's about it. your script does all the work, cron just calls it. For more information about crontab - use man crontab or man 5 crontab.
If your unclear how to schedule sending an email - that's 2 tasks scheduling (which is above) and a script that sends an email - which you can do any number of ways (such as using swiftmailer. Pick a technique and ask another specific question if you are stuck).
I don't have much idea about cron. But once I tried firing mail using cron. My php site folder is home/USER/www. So this is what I did:
1. created a txt file: cron.txt
2. placed cron required informtion : 29 16 * * * php /home/USER/www/test_cron.php
3. ( test_cron.php contains code for a dummy mail )
4. opened terminal and executed command : crontab cron.txt
and its been two month and I daily get an email on 4:29pm
Hope this information will help you.
Any help or ideas would be appreciated.
More information would be appreciated. Where do you run into problems? Is it in the scheduling? If so, do a Google search for "Scheduled tasks" in case the webserver is running Windows, or "Cronjobs" if the webserver is running Linux, Unix or BSD.
E-mail a file is rather simple if you use a library; I would suggest looking into attaching files with Swiftmailer.
hi i am working on send email every day 10am so i search lot of sites so i find using crone then it's possible to send email actually iam new to using crone so how can i install crone in my server please provide me some samples on sending email using php with crone.
Thanks for advance.
cron is probably already installed on your server. you will access it with:
crontab -e
To make it email with php you will probably want to use something like this: http://pear.php.net/package/Net_SMTP/
Cron is the inbuilt functionality provided by linux. it is a task scheduler. you need to set the cron to execute a php script every day at 10 am. this php script will contain the code for sending emails.
To see already set cron jobs use crontab -l to set new cron jobs use crontab -e. Your cron job looks as follows
1 2 3 4 5 /path/to/command arg1 arg2 OR 1 2 3 4 5 /root/backup.sh
Where,
1: Minute (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 [12 == December])
5: Day of the week(0-7 [7 or 0 == sunday])
/path/to/command - Script or command name to schedule
Check this link for more details How to Cron jobs
Also you may need to set the path to php executable in your php script, something like
#!/path/to/php/executable
as cron is Linux command it need to know which program to use to execute the given script. the above line goes as a first line before opening php tags.
Setup the cronjob:
$>crontab -e # this command line command sets up the cronjob and opens the vi editor
Linux Crontab Format
MIN HOUR DOM MON DOW CMD
Vi editor opens: add your script there:
Example:
25 11 * * * .csh 2014_09_16 --> This will execute the csh script daily at 11:25am and send an email accordingly
Esc- Shift+zz to exit the editor by saving the changes
$>crontab -l # this cmd checks if the conjob is set
You can easily execute a PHP file using cronjobs, and let it take care of your email sending. I've written a tutorial here: http://rapliandras.hu/blog/how-to-execute-php-scripts-as-cronjobs/
If you are unsure of how exactly an email is sent using PHP, check out its mail function's documentation here: http://php.net/manual/en/function.mail.php