Victor Hugo
Victor Hugo

Reputation: 109

What is the concept when creating an automatic send of email app on php

I have an website running, and what I want to do is create a Table that has listed all the email that need to be sent, with all the information in it. Example:

CREATE TABLE Send_Email
ID INT,
To VARCHAR(130),
Subject VARCHAR(130),
Message TEXT

What I want to do - and don't know how - is to check automatically if there is any record on this table, if there is: Send the email(s) and delete the row(s).

What I don't know is what is the concept when building something like this. Where to put it? How to check it automatically? Do I put the loop code on my main "master controller" and run it every time someone loads up one of my pages? This looks like it will affect performance.

Upvotes: 1

Views: 95

Answers (1)

0x5C91
0x5C91

Reputation: 3515

This is the ideal task for a cron job (or any equivalent system). You need a service running on your server, which will periodically perform your wanted action. If you have your own server, this can be done for sure, but if you have your site hosted somewhere you need to check with the provider for this possibility.

EDIT: If you can't use scheduled jobs, it might still be reasonable to perform the action somewhere else. For example, if the records in the table are inserted only from within your website, you could configure it to forward an email as soon as it is sent by the writer, avoiding the need to regularly check the database (in fact, you wouldn't need a table at all). It is obvious though that this solution is not as flexible as the other one, and that it is applicable only in particular situations.

Upvotes: 4

Related Questions