Re: [Djulia] Notice: CMSB v2.16 Beta!
Hi Djulia,
That's an interesting idea. Right now that only way to add backgroundSend messages to the _outgoing_mail table is to do so manually with MySQL.
The issue that we had is that when we want to send messages in the background there was usually lots of them (1,000 or more). I was concerned about PHP timing out if I called sendMessage() or emailTemplate_loadFromDB() in a loop.
So we were doing the mail merge in MySQL to avoid putting too much load on the server.
If you just wanted to put a few message in the Background Send queue, though, you could use some code like this:
$placeholders = array(
'datetime' => date('D, d M Y H:i:s'), // example use of placeholders
);
$emailHeaders = emailTemplate_loadFromDB(array(
'template_id' => 'USER-ACTION-NOTIFICATION',
'template_table' => 'email_templates',
'placeholders' => $placeholders,
));
if (!@$emailHeaders['disabled']) {
$colsToValues = array_slice_keys($emailHeaders, 'from', 'to', 'subject', 'html');
$colsToValues['createdDate'] = mysql_datetime();
$colsToValues['backgroundSend'] = '1';
$hideMysqlWarnings = true; // hide warnings if you don't define all the fields
mysql_insert('_outgoing_mail', $colsToValues, $hideMysqlWarnings);
}
If we wanted a function for that maybe we could call it sendBackground() to go with sendMessage() that way you could still wrap the emailTemplate functions and it would be explicitly clear in the code that a message was being queued for the background instead of sent.
eg: sendBackground(emailTemplate_loadFromDB($options)) ;
There's the still issue of timeouts though, so I'm not sure that I want to create that function as it might encourage programmers (at itools and elsewhere) to use it and end up running into timeout issues. Or maybe I'll just put a comment above the function warning about timeout issues so they can choose based on the project.
Let me know what you think and if you'd use that function. Thanks!
Dave Edis - Senior Developer
interactivetools.com