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

<pre><code>$email-&gt;cc = array(
    array('name' =&gt; 'Your Name', 'email' =&gt; 'name@example.com')
);
</code></pre>

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

CC BY-SA 3.0
2014-06-21T13:15:20.707Z
2014-06-21T13:15:20.707Z
Stuart Whitehead
<p>I'm trying to edit the Contact Form plugin to copy the email to another address.</p>

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

<pre class="lang-php prettyprint-override"><code>'cc' =&gt; array(AttributeType::Mixed);
</code></pre>

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

<pre class="lang-php prettyprint-override"><code>// Add any CC's
if (!empty($emailModel-&gt;cc))
{
    foreach ($emailModel-&gt;cc as $cc)
    {
        if (!empty($cc['email']))
        {
            $ccEmail = $cc['email'];

            $ccName = !empty($cc['name']) ? $cc['name'] : '';
            $email-&gt;addCC($ccEmail, $ccName);
        }
    }
}
</code></pre>

<p>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):</p>

<pre class="lang-php prettyprint-override"><code>$email-&gt;cc = array('email' =&gt; 'name@domain.com');
</code></pre>

<p>I've also tried this:</p>

<pre class="lang-php prettyprint-override"><code>$email-&gt;cc = array('email' =&gt; 'name@domain.com', 'name' =&gt; 'My Name');
</code></pre>

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

<plugin-development><plugins><emails>
Adding CC to contact form plugin
# Adding CC to contact form plugin

(Asked by: username_0 on 2014-06-21)

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?

**Tags:** plugin-development, plugins, emails


---

## 1 answers

### Answer by username_1 on 2014-06-21. Score: 5 | Accepted answer

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.


---

