Question

I need tos et up my application to send out periodic emails for my social networking site. The frequency of emails would be very sporadic based upon user interactions. FOr example my site has a QnA module - I allow users to follow questions, so every time an answer is posted all followers of the question would get an email.

I was thinking of implementing this using a cron job which would run periodically in the back ground at 5-10 minute intervals. The idea is that whenever an update is made an entry is made into a database with the list of recipients and email body. A cron job would then periodically check the database for any such jobs and execute it upon which the job would be marked as executed.

I was wondering if theres anything open source which can help me here. I just need code which sends emails in the background and all I have to provide it is the database table for the emails to send to as well as the email body.

Was it helpful?

Solution

Mail() with php
Sending bulk email in PHP
Sending mass email using PHP
Best way to send 10,000+ emails with PEAR/Mail_Queue
How can I debug a PHP CRON script that does not appear to be running?
Cron job to execute a PHP program

If you already have database writing your own php script is not that hard just use default mail() or some other lib (as suggested swift) function and put it elements form database, then just run that script with cron. Sure i may be wrong since i'm python programmer, but in the way i see its just a mailing function with cycle and some SQL query that would give for example 5 mails each minute.

Pros of that:

  • You will learn something (most probably).
  • You will spend less time than searching for openSource alternative that will require some editing that will suit you needs.

OTHER TIPS

Take a look at Swift mailer (http://swiftmailer.org) and phpMailer (http://phpmailer.worxware.com).

assuming your server has mail(), you should just be able to do something like this

$sql = ;//Sql query to grab data
$rs = ;// Result of sql query
if(sizeof($rs) > 0)
{
    foreach($rs as $item)
    {
        mail($to, $subject, $message, $headers);
        // SQL query to update rows saying its been sent out or something like that
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top