php form to email on scheduled time / date [closed] - php

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am going to do a basic form to email script, which is not a problem where you press send and the email goes. but what i want to do is i want to put additional fields in there for date and time and the email will go on that particular date/time. what is the best way to achieve this?
so for example at tuesday 13:30 i would like this script to run to send the email
send-mail.php?mail_id=4
and tuesday 13:45 send-mail.php?mail_id=5 where mail_id changes the mail recipients, content etc.
do i need to run another script every single minute to check in mysql if there is anything to be send? like
select * from mails where datetime = NOW() and if yes do the script? i dont think it is very good option as mysql will run 24/7 .
what are you recommendations

You could have a cron job that runs every 15 minutes and runs a sql statement like:
select * from mails where datetime <= NOW() AND isSent = 0
This would send all emails that are less then or equal to the current time. Make sure you update the record so you know it has been sent.

Related

Send auto email on delay for each MySQL entry [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I currently have a MySQL database that sends an auto email each time a new record is entered. I need to also send a reminder email to the email address in each row 5 days after it is inserted. What is the best way to do this? Can I use a MySQL trigger or a cron job? I will likely need step by step instructions, if it isn't through PHP. I've done quite a bit of searching but can't find exactly what I'm looking for.
A cron job is what you need. The php file doing the cron needs to query the table for rows where the entry date is equal to 5 days ago. The mysql query is:
SELECT `email` FROM `entries` WHERE date(`entrytimestamp`) = date_sub(curdate(), INVERVAL 5 DAY);
Hopefully this gets you started in the right direction. You'll need to make sure that the php file cannot be called outside of cron, that cron only happens once a day, or maybe keep a separate table logging the emails where you would add a "NOT IN email_log" condition to make sure that you don't double up on emails to someone.

How can I time something in PHP? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I want to do on a script I`m working on that every month a part of the site resets.
Or a better example, Something like a Subscription, when you want to buy something and you need to renew it every month. How can I know its been a month?
In PHP you can't do regular cron jobs, and I will discourage you seriously from doing it with real cron jobs if you don't know what you're doing.
You can only register when you last executed that event and then check if it's been a month since then. This is a really simple sample cron:
<?php
$lastexecution = /*logic to know when you last executed.*/;
/* It's either a database or a file or something similar.
* I usually use a database table that contains the records when I
* last executed a cron
*/
if (time() > $lastexecution + (30 * 24 * 3600)) {
/*CRON LOGIC*/
}
You also should look into flock() or some similar locking mechanism to prevent the cron being triggered by two different users simultaneously.
Note: In your case, with a subscription, you could add a expires field to your database that would contain the date and time when the user's subscription needs to be renewed. If that date is in the past, you tell them

Background update in database using php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
We have a database table with created datetime and status flag. We would like to update the status flag to the next status if the created date time has elapsed by 30 minutes without any user intervention. How can we achieve this in php.
Create a php file that does this status change in the database and program to execute it every 30 minutes with cron (Linux) or Task Scheduler (Windows).
You have to think carefully about how you design and use your database. Sometimes things are made overly complicated when they don't need to. For instance, in this case you could use a 'datetime' in your table indicating the start time. Any PHP script can now check whether or not the start time started 30 minutes ago, only when this information is actually needed. No need for a flag, cron jobs, etc.

Creating subscription for website [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I would like some guidance in this. I am creating an update for a website that will allow a customer to subscribe to buy ebooks and have them sent out each month and automatically bill. I know how to use a sql database and PHP to keep track of members etc, but how do I make my website so that it will schedule things automatically at certain intervals. I tried Google searching, but maybe I didn't know how to phrase it.
With the help of Cron Job, on Linux hosts. Cron job can be used to automate your php script. So you write a script that does what you want and schedule it with Cron. Best approach is to write in the table when do you want Cron to run. For instance:
You have a column named "SendBook" with the date when the book should be sent. You set your php script to check if today is that date and if it is, send the book. For more help, visit this site
Code example:
$sevendays = date('Y-m-d', strtotime("+7 days")); // date is set to seven days from now
$sql= "INSERT INTO tablename (SendBook) VALUES ('$sevendays')"; // date is passed to the table
mysql_query($sql);
Than you create php script that checks if today is that date:
$checkdate = date("Y-m-d");
$sql = "SELECT SendBook AS '$comparedate' FROM tablename";
mysql_query($sql);
if ($checkdate == $comparedate){
// send email or whatever you want to do
}
Than simply make second script run whenever you want with Cron

Will a CRON job be suitable for this? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have a database with an email address, an interval of how often someone wants an email sent to them (ranges from every 5 minutes to every couple of days) and the time at which an email was last sent. I currently have a PHP script that runs through the database and finds times before the current time and sends them an email and updates the time at which it is scheduled send the new email (using the interval).
Would it be OK to set this script up as a CRON job and run it every say 4 minutes? Or would this create too much overhead? I have 500+ tuples of data that it will need to traverse every 4 minutes.
First off, don't send anyone an email unless they have requested it specifically or your sever will be black listed for spam and no emails will get through.
Second, a cron job is perfect for that kind of job. If the maximum rate is one email every 5 minutes there would be an average of 100 emails every 1 minute cron run (if everyone for some mind boggling reason did decide to have an email that frequently)
Yes, this is a good candidate for a CRON job. No, it's not too much processing overhead to run this every 4 minutes. You should use SQL to query only those rows that may need an email, and running such a query should take about 25 ms.
But from a business perspective, once per day (every 24 hours) or a few times per day should be sufficient & indeed preferable. As the commenter above said.

Categories