Take the 2-minute tour ×
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It's 100% free, no registration required.

I'm trying to edit the Contact Form plugin to copy the email to another address.

Looking in apps/models/EmailModel.php I see this for CC:

'cc' => array(AttributeType::Mixed);

Looking in apps/services/EmailService.php I see this:

// Add any CC's
if (!empty($emailModel->cc))
{
    foreach ($emailModel->cc as $cc)
    {
        if (!empty($cc['email']))
        {
            $ccEmail = $cc['email'];

            $ccName = !empty($cc['name']) ? $cc['name'] : '';
            $email->addCC($ccEmail, $ccName);
        }
    }
}

So, it looks like 'cc' needs to be array? I tried it without it being an array and I get an invalid foreach error. At the moment, I've added this line to ContactFormService.php (after line 45):

$email->cc = array('email' => 'name@domain.com');

I've also tried this:

$email->cc = array('email' => 'name@domain.com', 'name' => 'My Name');

The problem: The email is not being CC'd and I'm not getting any errors. Anyone?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

From that code snippet, it looks like you're needing nested arrays. Try setting your $email->cc property like this.

$email->cc = array(
    array('name' => 'Your Name', 'email' => 'name@example.com')
);

The code snippet is iterating over $email->cc as $cc as the first array, then going into cc['name'] and cc['email'] as a nested array.

share|improve this answer
    
Perfect. Thanks. –  Clive Portman Jun 21 at 13:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.