Link to Github repository for plugin: https://github.com/pixelandtonic/ContactForm

Being given an error by the plugin where it is interpreting my Twig variable literally as a string instead of what the variable is representing. I am looking for a way to fix this using the current set-up but having an alternate setup is fine as well. Also for reference, I have followed the guidelines on the README in regards to changing the craft/config/contactform.php file. Much appreciated for the help!

This is my code:

{% macro errorList(errors) %}
{% if errors %}
    <ul class="errors">
        {% for error in errors %}
            <li><span>{{ error }}</span></li>
        {% endfor %}
{% endif %}
{% endmacro %}

{% from _self import errorList %}

<div class="uk-width-large-1-2 uk-width-medium-1-2 uk-width-small-1-1 uk-container-center">
<form method="post" action="" accept-charset="UTF-8">
    {{ getCsrfInput() }}
    <input type="hidden" name="action" value="contactForm/sendMessage">

    <ul id="button-content" class="uk-switcher uk-margin">
        <li class="text-space basic-border">
            <h3><b>Email to {{default.defaultcontactreason}}</b></h3>
            <input type="hidden" name="toEmail" value="{{ '{{default.defaultContactEmail}}'|hash }}">{{default.defaultContactEmail}}
    {% for category in craft.entries.section('Contacts') %}
        <li class="text-space basic-border">
            <h3><b>Email to {{ category.contactReason }}</b></h3>
            <input type="hidden" name="toEmail" value="{{ '{{category.contactEmail}}'|hash }}">{{category.contactEmail}}
    {% endfor %}

    <h3><label for="fromName">Your Name</label></h3>
    <input id="fromName" type="text" name="fromName" value="{% if message is defined %}{{ message.fromName }}{% endif %}">
    {{ message is defined and message ? errorList(message.getErrors('fromName')) }}

    <h3><label for="fromEmail">Your Email</label></h3>
    <input id="fromEmail" type="text" name="fromEmail" value="{% if message is defined %}{{ message.fromEmail }}{% endif %}">
    {{ message is defined and message ? errorList(message.getErrors('fromEmail')) }}

    <h3><label for="subject">Subject</label></h3>
    <input id="subject" type="text" name="subject" value="{% if message is defined %}{{ message.subject }}{% endif %}">
    {{ message is defined and message ? errorList(message.getErrors('subject')) }}

    <h3><label for="message">Message</label></h3>
    <textarea rows="10" cols="40" id="message" name="message">{% if message is defined %}{{ message.message }}{% endif %}</textarea>
    {{ message is defined and message ? errorList(message.getErrors('message')) }}

    <input type="submit" value="Send">
    <input type="hidden" name="redirect" value="{{siteUrl}}Contacts">
  • for reference, the exact exception reads: Invalid address: {{category.contactEmail}}
    – Matthew
    Commented Jun 30, 2016 at 20:54

1 Answer 1


Looks like you've got some nested escape tags in Twig, which is a no-no.

value="{{ '{{category.contactEmail}}'|hash }}"

You just need to use:

value="{{ category.contactEmail|hash }}"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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