简体   繁体   中英

PHP - Send an e-mail with a delay of x time

I need send and email after x time using a php code.

I don't want use cronjob. so, this code doesn't works because the php code it's print one time and doesn't change the DOM automatically like js. But I need something like this:

  $today = date('Y-m-d H:i:s');
  $dataorder = date("Y-m-d H:i:s", $order->created);
  $delay_days = 240;
  $senday = date('Y-m-d H:i:s', strtotime( "$dataorder + $delay_days min" ));

   if ($today == $senday) {

    echo "sent";

   } else {

    echo "not yet sent";

   }

Now, I can use js, but I'm not sure if this will work, this php script is an all php page in the backend. so, can I use only php? like use sleep function? or other one

I don't know with is the best way.

(Specifically it is a system of sending emails to remember to leave a commend on the site.)

Thank you

You can achieve this as,

  1. As you have data of user\\'s you know on which date a particular user is registered.

  2. Write a script which will execute every day & will select all the user's registered 5 days ago. Mail will be sent to all the user's matched for that date.

  3. Script will continue to execute till last user is processed for that date.

You can store every email in database table or a temp file and when it's time user action will send pending emails. You can make a ajax request every 10 seconds for example which will send mails to prevent slow loading of page.

Better solution is if you use a cronjob for jobs like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM