Notice: CMSB v2.16 Beta!

34 posts by 6 authors in: Forums > CMS Builder
Last Post: August 28, 2012   (RSS)

By Djulia - August 27, 2012 - edited: August 27, 2012

Hi Dave,

>Can you explain more...

In fact, I wondered whether it were possible with the function emailTemplate_loadFromDB(), not to send the email but to record in the _outgoing_mail table and to choose if it will be sent or will not be sent since a cronjob.

'logging' => true,
'backgroundSend' => 0/1,

It would be then possible to use the _outgoing_mail table with different plugins (with need different).

Thanks!

Djulia

Re: [Djulia] Notice: CMSB v2.16 Beta!

By Dave - August 27, 2012

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

By Djulia - August 28, 2012

Hi Dave,

I made some test and I find this function very interesting. That also gives a potential interesting for the _outgoing_mail table.

Thanks again for your patience!

Djulia