<p>As of <a href="https://craftcms.com/changelog#build2916" rel="nofollow">Craft 2.6.2916</a>, the email fields are no longer ran through Twig's safe mode.</p>

<blockquote>
  <p>EmailService no longer has Twig render email messages in safe mode, which was a little heavy-handed and prevented email message templates from accessing global variables and other things.</p>
</blockquote>

CC BY-SA 3.0
2016-08-25T19:12:02.977Z
2016-08-25T19:12:02.977Z
Brad Bell
<p>OK so it's pretty easy to pass additional variables to the email template using the <a href="https://craftcms.com/docs/plugins/events-reference#email-onBeforeSendEmail" rel="nofollow"><code>email.onBeforeSendEmail</code></a> event:</p>

<pre><code>craft()-&gt;on('email.onBeforeSendEmail', function(Event $event)
{
    $event-&gt;params['variables']['craft'] = new CraftVariable();
});
</code></pre>

<p>Although I guess there are security reasons for email templates being rendered in safe mode in the first place so I don't know how much of a good idea this is...</p>

CC BY-SA 3.0
2016-08-25T15:25:42.383Z
2016-08-25T15:25:42.383Z
Mike Pepper
<blockquote>
  <p>EmailService now has Twig render email messages in safe mode.</p>
  
  <p>-- <a href="https://craftcms.com/changelog#build2903" rel="noreferrer">https://craftcms.com/changelog#build2903</a></p>
</blockquote>

<p>I don't think this is really a bug as it's intended behaviour, but this is causing me a pretty big issue because my email layout has code in it like:</p>

<p><code>{% set contactDetails = craft.globals.getSetByHandle('contactDetails') -%}</code></p>

<p>But I think safe mode now means that the <code>craft</code> variable isn't actually available. I can pass it in manually when I'm sending non-standard emails with <code>craft()-&gt;emails-&gt;sendEmail()</code>, but has anyone found a way around this for the built-in ones like the activation/verification emails?</p>

<emails>
EmailService now has Twig render email messages in safe mode
# EmailService now has Twig render email messages in safe mode

(Asked by: username_0 on 2016-08-25)

> EmailService now has Twig render email messages in safe mode.
>
> -- <https://craftcms.com/changelog#build2903>

I don't think this is really a bug as it's intended behaviour, but this is causing me a pretty big issue because my email layout has code in it like:

`{% set contactDetails = craft.globals.getSetByHandle('contactDetails') -%}`

But I think safe mode now means that the `craft` variable isn't actually available. I can pass it in manually when I'm sending non-standard emails with `craft()->emails->sendEmail()`, but has anyone found a way around this for the built-in ones like the activation/verification emails?

**Tags:** emails

---

## 2 answers

### Answer by username_1 on 2016-08-25. Score: 3 | Accepted answer

As of [Craft 2.6.2916](https://craftcms.com/changelog#build2916), the email fields are no longer ran through Twig's safe mode.

> EmailService no longer has Twig render email messages in safe mode, which was a little heavy-handed and prevented email message templates from accessing global variables and other things.


---

### Answer by username_0 on 2016-08-25. Score: 4

OK so it's pretty easy to pass additional variables to the email template using the email.onBeforeSendEmail event:
craft()->on('email.onBeforeSendEmail', function(Event $event)
{
    $event->params['variables']['craft'] = new CraftVariable();
});

Although I guess there are security reasons for email templates being rendered in safe mode in the first place so I don't know how much of a good idea this is...


---

