I am making a website that sends people who sign up for it an email every day in the morning. The problem I have run into is that I don't know how to send an email at the same time everyday in php. I do know how to send an email, all I need to know how to send one daily.
You can setup a CronJob for that. Only make the PHP that sends the email you want and prepare a CronJob in your server that executes every day (you can specify the time of the day).
I would use Tectite Formmail
If you have, for example, GoDaddy hosting, you can follow this instructions: CronJob GoDaddy
Yes, you need to run cron, it will already be installed and configured on your server.
To build-up your list, set up a form that subscribes people to your list, adding them to a database - don't forget to use double-opt-in.
Then write a PHP script that generates a message for everyone on your list and sends it to them - there is a code example that does exactly this bundled with PHPMailer. To let cron know how to run the script, make this the first line of the file (before <?php):
#!/usr/bin/env php
Finally, get cron to run it - this is trivially simple - just symlink it into /etc/cron.daily/ and it will get run when cron runs each day. Look in /etc/crontab to see when this is, and alter it if you like. For example:
ln -s /path/to/my/script /etc/cron.daily/myscript
Related
I am a new user of Yii framwork, and I have implement YiiMail, which works well. But now I want to send mails automatically at the end of each month, is it possible?
Steps are as follows:
Set up a crontab on your server, that will run a PHP command.On Windows you can set a scheduled task which will run <yourdir>/protected/yiic-dev.bat with the proper commands to run (take a look at CConsoleCommand), which will send the emails.On the production server, you do the same but with php <yourdir>/protected/yiic.php as the cron with the command to run as argument, which will do the same but on a Linux environment (if it's a Windows server, just make a scheduled command for <yourdir>/protected/yiic.bat and the proper arguments)
Send the emails in the corresponding action, by using the mail class (see the documentation for YiiMailer)
If there are further problems and you run into more specific issues you can't work around, I suggest you make new questions for them.
I have found that there is related topic.However, there are some difference because the people is asking for ubuntu server but i am using the Apache (xampp****) the latest version, so are there any method to let the system automatically send mail by checking the date ?
Can it applies to some schedule sending as well? thanks
I have the script for sending it , the only thing i need is how to schedule send.
Edit:
Make it simpler , assuming only windows is the only platform. Can i do some php script and create the cron job in os , so that my client can schedule their mail in my system instead of doing it in the os?
3 rd party cron job is good suggestion but there is limitation (what if their service break down etc...) and i want everything is based on own system
If your xampp is on Windows, you can use windows-schedulers to call a particular script (PHP script in your case, preferably by an URL), which checks the birthdays of all the users and sends them mail accordingly.
If your xampp is on Linux/Unix/etc, you can use cron-jobs, and rest is same!
There is also a third way, a third-party scheduler or say online-cron, which will remotely call yours script (php-page).
Example:
If you are doing the cron-settings of OS yourself, you can still let the configure as to whom to email in your system, rather than OS.
After all, a cron so is to do something repeatedly, in your case, its just calling your scripts, by an URL.
Now regarding the time settings, you can make the CRON call your script every hour, and your php script will check the appropriate time, and fire the mails!
schedule a script in crontab or scheduler which will check the birthday of your customer
and send them an email
this script will run everyday at particular time of the day
use server cron job to run a script that will send out email. ur script should compare current's date and customer's birthday date.
You could use a cron-job. With PHP that get all the people that you want to send an email and gets template and send it just substitute the name and other stuff
You may use Wishing Application. Getting started provides good details on how to kick started. At minimal you need only two things the excel file having wish details (Birthday and on work anniversary), and a configuration file (application.properties) to provide the mapping details and other configurations. There are various options to run this application, locally (background, foreground, docker, windows-scheduler etc) on cloud
Disclaimer : I am the owner of application.
We are running a webinar. I want to send reminder email to all those registered on my site 3 days before the webinar.
The registrant details are in my MySQL and it is a PHP website.
How do I do that?
Any help would be highly appreciated!
Thanks,
PHP can't do that by itself as it is not a program running constantly on a server. It is only run when a user requests a web page. You would need to set up a cron job on the server that calls a PHP script to do the emails.
First, your database would need a field that says whether you have already sent the email or not. Your PHP email script would check if it is 3 days or less until the event, and you have not already sent an email to that person, then send it.
Then you would call that script from a cron job. You can run PHP from the command line, or alternatively use something like curl or wget to fetch the URL as if you were running the script in a web browser. (That would also mean you can run the cron job from another computer if necessary.)
You could set a cronjob to run a reminder script at a specific time 3 days before your webinar. Your script would loop through your user data and send email using some variation of php's mail function.
Not sure what your server type is but if you are running cPanel here is a link to their docs on how to set up a cron job:
http://docs.cpanel.net/twiki/bin/view/AllDocumentation/CpanelDocs/CronJobs
Let us know which of the above you're not sure about and we can provide some more info.
PHP doesn't have built-in schedulers.
You should consider using cron on unix/linux
or
Schedulers on Windows
or
There are some online crons available.
which will call your php-scripts. (which will internally do the task of mailing)
Note: the links above refer to drupal sites, but explanations given there with regards to cron and schedulers are applicable in pure-php.
I'm making a website that need's a cron job or a scheduled task to send emails weekly but the problem is that I don't know if the host supports it...
This website is for an institution and I can't put it in any other host...
The host is using Apache.
If it doesn't support, how can I send weekly emails automatically, without changing host?
EDIT
I forgot to say that I'm new in cron jobs.
Apache has nothing to do with cron jobs as the system running on the host must trigger the job (which then can invoke a script running under apache).
Do you have SSH access?
Add the job to the /etc/crontab file or the cron-file of your user.
Or do you have a Webinterface to some management software (e.g. Plesk)?
Search there for an option for Cron jobs or Scheduled tasks.
If not you can use some external services which will call an URL on you site to trigger the job like http://www.setcronjob.com/.
First, ask your host if cron jobs are supported (they should be), check your panel (if there is one), try to set up one and see if it works etc.
If not, one possible way (other than to find an external service that will do the call to the script for you) is to add a function to your code that will be called every time a visitor of your site enters a specific page (e.g. the index). There, you will check if the weekday is the day that you want to send the e-mail. If yes, then send the mail, having a flag (e.g. a record in the db) to check if it has already been sent.
Of course it's not the ideal solution, all the others (the actual crons or an external service) are better, but since it is a solution, it's worth mentioning.
Have you read some documentation about cron-daemon?
This code is check the the cron is running
ps -ef | grep cron
After then you need to create a file which can handle the email address pickups and send th mails.
And also need to add something like this to the cron (it just an example send out something at every sunday, 23 o'clock):
0 23 ? * 0 php /path/sendnewsletter.php
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.