Automatic Mail Sending on specific Dates in PHP

前端 未结 5 1571
春和景丽
春和景丽 2020-12-22 07:24

I am having some mail ids in my database. I have to send mail to those mail ids automatically on some specific dates that i have mentioned in my database.How to do that in p

5条回答
  •  孤城傲影
    2020-12-22 07:52

    Here are a few general steps of the logic that you can follow:

    The PHP script should:

    • extract the email addresses and the specific dates from your database into arrays.
    • check whether today's date is in the array containing the dates. Be sure to format the date appropriately!
    • loop through the email addresses (preferably in a foreach() loop), if the above check returns 'true'.
    • within this loop, use PHP's mail() function to send your email.

    Your next step would be to set up a scheduled task that runs this script daily, usually by means of a cron job. This step depends on the server you've got.

    NOTE: These steps illustrate the most basic way to do what you require. There may be other, more complex ways that would be faster, cleaner and less intensive on your server.

提交回复
热议问题