1

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?

Christian Webb
  • 297
  • 1
  • 6
  • 14

2 Answers2

0

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.

Wes
  • 950
  • 5
  • 12
0

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.

Ahmad Alinat
  • 141
  • 8