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 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.

By Dave - October 30, 2013

Hi Paul,

I think you're close.  Can you try replacing 'Bcc' with 'BCC' in your original code.  I think it's might be a case-sensitivity issue.

Let me know if that works, thanks!

Dave Edis - Senior Developer
interactivetools.com