Before I tackle this solution, I wanted to run it by the community to get feedback.
Questions:
- Is my approach feasible? i.e. can it even be done this way?
- Is it the right/most efficient solution?
- If it isn’t the right solution, what would be a better approach?
Problems:
- Need to send mass emails through the application.
- The shared hosted server only permits a maximum of 500 emails to be sent per hour before getting labeled a spammer
- Server timeout while sending batch emails
Proposed Solution:
Upon task submittal (i.e. the user provides all necessary email information using a form and frontend template, selects the target audience, etc..), the action will then:
- Determines how many records (from a stored db of contacts) the email will be sent to
- If the number of records in #1 above is more than 400:
- Assign a batch number to all these records in the DB.
- Run a CRON job that:
- Every hour, selects 400 records in batch “X” and sends the saved email template until there are no more records with batch “X”. Each time a batch of 400 is sent, it’s batch number is erased (so it won’t be selected again the following hour).
- If there is an unfinished CRON JOB scheduled ahead of it (i.e. currently running), it will be placed in a queue.
Other clarification: To send these emails I simply iterate over the SWIFT mailer using the following code:
foreach($list as $record)
{
mailers::sendMemberSpam($record, $emailParamsArray);
// where the above simply contains: sfContext::getInstance()->getMailer()->send($message);
}
*where $list is the list of records with a batch_number of “X”.
I’m not sure this is the most efficient of solutions, because it seems to be bogging down the server, and will eventually time out if the list or email is long.
So, I’m just looking for opinions at this point... thanks in advance.