简体   繁体   中英

sending email from the database automatically

Is it possible to send a automatic mail from database depending on the date? When date is equal to some Particular date , emain should go to the user.

I have created my database table in mysql like this:

create table tb1(name varchar(20), email varchar(30), date varchar(10));

I will be using php. Please suggest me how to do it?

At first, as answer of a1ex07 you have use status fields to filter message to send. Filter your messages with query and with a loop send the message info to(with get method) php script(send.php) that listens 'query string' of the message to send .

To trigger your php you can include querylist page into your web site or web app.

Traditional approach:
Depends on OS you can set up a scheduled task(cron job) that runs with a certain interval (I think it doesn't have to be very accurate, 3-5 minutes seems ok to me), grabs expired rows from the table, send emails and mark the records (I suggest adding email_status column ) based on delivery status (success, failure, bounced, etc). You might want to add another column for storing mail server response.

Another option is more complex. You can write a native UDF that is capable of sending emails. Then you create recurring event that calls this function . It can be a good exercise, but may not be the best solution. Pros : completely done on server side, no client code required. Cons: creating and debugging native function can be a challenge, the function has to be uploaded to server instance, logic resides on database server

create a php file to check the current date with the date in the database, if they match use mail() to send the email to that user.

you can also use CRON to run the file as often as you would like ( I would suggest nothing more often than 24 hours).

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