Adding headers to email templates

4 posts by 3 authors in: Forums > CMS Builder
Last Post: October 30, 2013   (RSS)

By pault - October 8, 2013

I would like to use the email template system to send emails but need to be able to Bcc each email to a specific address.

I've tried to set this up but can't get it to work, I've tried the following:

$emailHeaders = emailTemplate_loadFromDB(array(
              'template_id'  => 'USER-SIGNUP',
              'headers' => array(
                'Bcc'   => 'email@address.com',
              ),
              'placeholders' => array(
                'username'   => $_POST['email'],
            )));
            $mailErrors   = sendMessage($emailHeaders);

Please can you tell me if it's possible and if so, where I'm going wrong?

Thanks, Paul.

By ross - October 17, 2013

Hi Paul

Thanks for posting!

I see what you are aiming for and I think we can look at the code to make headers available.  What is it that triggers the emails being sent? It is a simple contact form on your site somewhere? What I am thinking of as an alternative would be to just setup a second sendMessage() call right after the first one. That way, you can send the second copy to another address.

Do you think that would work?

Let me know what you think. Thanks!

-----------------------------------------------------------
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com

Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/

By pault - October 21, 2013

Hi Ross,

Thanks for your reply.  I'm using the function to send message for various actions througout the site, for example when a user updates their profile.

I have done it at the moment using a second call to sendMessage but the reason I wanted to add additional headers was to add the Bcc to copy the site administrator so that not only can they see that an action has taken place but also who it was sent to and ay what time, etc.  If I use the second sendMessage() call as I am now, it's just sent To: the site administrator so they don't see who the original message was sent to.  Not a big deal, just a nice to have.

I noticed in the emailTemplate_loadFromDB function, which I'm using to populate the headers for sending, prior to calling sendMessage, there's the following code:

foreach ($passThruFields as $field) {
    if (!array_key_exists($field, $options)) { continue; }
    $emailHeaders[$field] = $options[$field];
}

Can this be used in someway to add the Bcc header?

Thanks, Paul.