How to schedule emails to send out

前端 未结 5 1705
独厮守ぢ
独厮守ぢ 2021-02-06 11:57

Using PHP, I have a query that goes through my DB looking for pending tasks with reminder triggers at certain times of the day. I have a cronjob that runs every 10 mins and chec

5条回答
  •  轮回少年
    2021-02-06 12:23

    PHP solution

    I have thought about your problem a little bit more and this is the PHP solution which I came up.

    #!/opt/lamp/bin/php is the path to my php interpreter. You should change it to your path or just run it with php -f scheduler.php

    scheduler.php

    #!/opt/lampp/bin/php
    

    You should run this script from within a bash script to see what it does. Also the code has been documented pretty well. The script should run forever(in background).

    Java Solution

    This also isn't a PHP only solution, but I think this will scale better than the PHP solution I came up with. I am still working this, but I like what I came up with so far.

    Google App Engine Solution

    I know this is not a PHP solution, but when you can not install a message queue I think Google App Engine is the best solution. When I saw this video introduction from Brett Slatkin to google app engine using the Python SDK I was sold to Google App engine. It will only take 10 minutes of your time and you will learn how to create a basic guestbook and deploy it to the cloud. Below if interested I will try to explain which pieces you need to do this on Google's App Engine.


    I guess I'll need some sort of message queue system

    Maybe you could use the google app engine's taskqueue to qeueu the task. The taskqueue even has an eta which you can set to run at a specific time. Google App engine has a generous free quota. You can add 100,000 queues to the task free of charge every day.

    but how does the email part work

    I would use google app engine for this. You can use google app engine's mail service. It also has a generously free quota (2000 recipients a day). I would advise you just to cal the mail api from the queue to send the message.

提交回复
热议问题