I've created a new template file with a navigation menu and a contact form, which slides out with jquery when a link on the navigation is clicked, editing the form depending on which link is clicked.

This .phtml template file is loaded in the product view page, just below the add to cart form. It's basically an enquiry form for each product for a customer to send questions for this product.

As I need to display extra input fields (Product name, id & current url for example), I need to edit the e-mail template to support those extra vars.

1) Is there a way to define which Transaction E-mail Template is used for a specific form, or is this only possible with a custom module rather than a custom template phtml file?

The second issue is that I do not want to direct the customer to the contact page after submitting, but rather reload the product page with a notice that the message has been sent.

2) Is there a way to reload the product page with the notice msg after submitting the form, rather than being redirected to the contacts page?

---- EDIT1 ----

I've managed to do 2) by using the prototype ajax.update to submit via ajax - however it still needs to output the response from the contact form (the whole contact page with success message), which I just hide in a div with the id #noDisplay

My JS Script:

<script type="text/javascript">
    var formId = 'customContactForm';
    var myForm = new VarienForm(formId, true);
    var postUrl = '<?php echo $this->getUrl("contacts/index/post") ?>';

    function doAjax() {
        if (myForm.validator.validate()) {
            new Ajax.Updater(
                { success:'noDisplay' }, 
                postUrl, {
                    onComplete:function(request, json) {
                    onLoading:function(request, json){
                    parameters: $(formId).serialize(true),

    function FadeEffect(element, effectduration, effectdelay){
       new Effect.Fade(element, { duration:effectduration, delay:effectdelay });

    new Event.observe(formId, 'submit', function(e){
        FadeEffect('formSuccess', 2, 4);


Thanks in advance.

2 Answers 2


Your route contacts/index/post - I assume is part of the core Mage_Contacts module in Magento. If so, that template can be configured via Magento admin at System > Configuration > Contacts; see also:


If you were to inspect the controller, you would see it referenced:

# File: app/code/core/Mage/Contacts/controllers/IndexController.php
# postAction, lines ~96-99
$mailTemplate->setDesignConfig(array('area' => 'frontend'))

And the constant XML_PATH_EMAIL_TEMPLATE resolves to the configuration path contacts/email/email_template.

If you continue to read this postAction method, you can see that it passes the entire POST data to the template. Therefore, all of its data should be available to you during the transactional e-mail processing:

array('data' => $postObject) // $postObject Varien_Object

So your e-mail template can call in the POST data like so:

{{var data.getFormFieldName()}}

Now, regarding your AJAX response, you may have to override the controller in order to generate a useful JSON response. Otherwise the response is going to be the HTML output of the controller's _redirect call. If you did extend the controller to return your desired JSON, it can be accessed as the first parameter in your callback:

onComplete: function(transport) {
    var response = transport.responseText.evalJSON();

You cannot change the email template from the phtml template (or in the layout or anywhere without creating a custom module), it's specified in the controller action of Mage_Contacts and not intended to be dynamic.

But there is a solution for different emails without a custom module, which I already explained here: How to tell a Custom Contact Form to use a certain Transactional Template

  • create a hidden input that determines the type of the form. It could be just <input type="hidden" name="custom" value="1" />.
  • in the contact transactional email template, use the if directive to show different content based on the form type:

    {{if data.custom}}
        ... custom contact form email ...
        ... standard contact form email ...

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.