<p>You could write a plugin, which hooks in the contact form's <a href="https://github.com/pixelandtonic/ContactForm/blob/master/contactform/services/ContactFormService.php#L86-L89" rel="nofollow noreferrer"><code>onBeforeSend</code> event</a>, and modifies the recipients.</p>

<p>Here's an absolute bare-bones solution which does exactly that (not tested in any way whatsoever):</p>

<pre><code>&lt;?php namespace Craft;

class ExamplePlugin extends BasePlugin
{
    // Standard plugin methods omitted for brevity...

    public function init()
    {
        craft()-&gt;on('contactform.beforeSend', function (Event &amp;$event) {
            $event-&gt;toEmail = 'john@doe.com';
        });
    }
}
</code></pre>

<p>Whether or not this is "officially" supported is unclear.</p>

<p>The fact it's an event (as opposed to a hook) might suggest not, <em>but</em> the contact form does check whether any listeners modified the event data, as evidenced by its <a href="https://github.com/pixelandtonic/ContactForm/blob/master/contactform/services/ContactFormService.php#L30" rel="nofollow noreferrer">check of the <code>isValid</code> property</a>.</p>

CC BY-SA 3.0
2017-02-20T17:22:43.040Z
2017-02-20T17:22:43.040Z
Stephen Lewis
<p>I ended up with a simple piece of code in /craft/config/contactform.php</p>

<pre><code>namespace Craft;

switch (CRAFT_LOCALE) {
    case 'en': $cf_toEmail = 'english@domain.co.uk'; break;
    case 'de': $cf_toEmail = 'german@domain.de'; break;
    // .....
    default:   $cf_toEmail = null;
}

return array(
    'toEmail' => $cf_toEmail,
    'prependSender' => '('.craft()->request->getPost('fromEmail').')',
);
</code></pre>

<p><code>prependSender</code> in the return array was to troubleshoot another shortcoming that my clients do not like in the emails the CF plugin sends - that there is nowhere to see the <code>fromEmail</code> in the received email - it is only in the Reply-To header.</p>

<p>And I chose the config file over the plugin, as it's simpler and less code.</p>

CC BY-SA 3.0
2017-03-09T16:01:01.783Z
2017-03-09T16:01:01.783Z
Ross Dinchev
<p>What is the best way to define different sendto emails addresses for the ContactForm plugin, depending on the locale the site is currently viewed in?</p>

<p>I am setting up a multilanguage site, and the clients want to have different emails for each language version.</p>

<p>So far I figure a possible way would be to have separate, localized contactform templates, and in each of them define a dynamically-added recipient. But I wondered if there's a better option, e.g. locale-specific options in craft/config/contactform.php?</p>

<p>Thank you</p>

<localization><plugin-contactform>
Contact Form plugin - different recipients per locale
# Contact Form plugin - different recipients per locale

(Asked by: username_0 on 2017-02-20)

What is the best way to define different sendto emails addresses for the ContactForm plugin, depending on the locale the site is currently viewed in?

I am setting up a multilanguage site, and the clients want to have different emails for each language version.

So far I figure a possible way would be to have separate, localized contactform templates, and in each of them define a dynamically-added recipient. But I wondered if there's a better option, e.g. locale-specific options in craft/config/contactform.php?

Thank you

**Tags:** localization, plugin-contactform

---

## 2 answers

### Answer by username_1 on 2017-02-20. Score: 1

You could write a plugin, which hooks in the contact form's onBeforeSend event, and modifies the recipients.
Here's an absolute bare-bones solution which does exactly that (not tested in any way whatsoever):
on('contactform.beforeSend', function (Event &$event) {
            $event->toEmail = 'john@doe.com';
        });
    }
}

Whether or not this is "officially" supported is unclear.
The fact it's an event (as opposed to a hook) might suggest not, but the contact form does check whether any listeners modified the event data, as evidenced by its check of the isValid property.


---

### Answer by username_0 on 2017-03-09. Score: 0

I ended up with a simple piece of code in /craft/config/contactform.php
namespace Craft;

switch (CRAFT_LOCALE) {
    case 'en': $cf_toEmail = 'english@domain.co.uk'; break;
    case 'de': $cf_toEmail = 'german@domain.de'; break;
    // .....
    default:   $cf_toEmail = null;
}

return array(
    'toEmail' => $cf_toEmail,
    'prependSender' => '('.craft()->request->getPost('fromEmail').')',
);

prependSender in the return array was to troubleshoot another shortcoming that my clients do not like in the emails the CF plugin sends - that there is nowhere to see the fromEmail in the received email - it is only in the Reply-To header.
And I chose the config file over the plugin, as it's simpler and less code.


---

