Contact Form in Magento

53 Comments 2nd JAN 2009 | Posted by Tomislav Bilic in Magento

Contact Form in Magento

As you know, Magento has a built-in contact form that can be used for general contacts. That form isn’t part of any CMS page, you cannot edit some introduction text, you cannot add phone numbers administration, and you cannot see the breadcrumbs. If you wish to edit text in that default contact form, you will need to update front-end files. Luckily, there is an alternative.

If you are a developer, editing your contact form HTML is an easy task. You only need to open file:
app/design/frontend/default/[yourtheme]/template/contacts/form.phtml and you will find your way around.

Once there, you will basically edit the layout of this interface.

However, there are cases when you would like to give your client an option to edit some intro text, edit his phone numbers, edit text behind the form, etc. You are probably guessing that it would be nice to be able to embed contact form in some CMS page. No problem.

  • Go to your CMS> Manage Pages interface
  • Once there, input your HTML as you normally would on any other page
  • Once you are happy with HTML part, add this lines:
    <!– CONTACT FORM –>
    {{block type=”core/template” name=”contactForm” template=”contacts/form.phtml”}}
    <!– END OF CONTACT FORM –>

Here is how it looks like. Notice the breadcrumbs.

Contact Form

I know that this is not some breakthrough article, but I will certanly create contact CMS page on all of my future Magento projects.

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • NewsVine
  • Sphinn
  • Tumblr
  • Posterous

To post code in comments, place your code inside [code] and [/code] tags.

There are 53 comments (Add Yours +)

  • Hi,

    Your website is very helpful. Lot of useful magento related stuffs. I am facing a problem with “Send To Friend” module in magento.

    I want when anyone use the “Send to Friend” form to send an email (basically sharing a product) then copy of the same email will be sent at my email id as “BCC”.

    Can you please tell me how to do it? Which file I have to modify?

  • Hi Prashant,

    The email sending is triggered in the app/code/core/Mage/Sendfriend/model/Sendfriend.php

    Try to look at the whole app/code/core/Mage/Sendfriend folder and try to find a way to send BCC from there. I didn’t have a chance to play with it yet, but it is a good starting point.

    Keep in mind that actual HTML/Javascript is visible from app/design/frontend/default/[your_theme]/template/sendfriend/send.phtml

    I konow I didn’t give exact solution. If you find it, please share it here. If not, I’ll try to find it when I catch some time. :)

  • I got it!

    I have edited “public function send()” function in the file “app/code/core/Mage/Sendfriend/model/Sendfriend.php”

    In this file I added the following code line

    //Customization: following line is used to add the bcc, with every mail //which is sent from SendToFriend form.
    $this->_emailModel->addBcc(“sales@mywebsite.com”);

    below the this line

    foreach($this->_emails as $key => $email) {

    Now whenever anyone send mail (using send to friend form) to there recipient, each mail will also come at the BCC address. Like if user added 5 recipients then you will receive five emails at BCC address.

    It works for me, hope it helps!
    But @Tomislav please check this at your end that this is the right way to do this or we have some other easy way (I don’t think there is any).

    Thanks,
    Prashant

  • Where does the default contact us form send email to? How do you change that?

    Cheers,
    Chris

  • System> Configuration> General> Contacts

  • I checked my theme folders and I don’t have any one called “contact” in “template” subdirectory. It is the default magento theme…

    I can add a home made form but if magento has already ready form, I’d like better use it…

  • Thats the “from address” that gets put into email generated on the server. What is the email address that the contact form information gets sent to on submission?

  • @Prashant

    Thanks for the input. But where exactly do I insert the codes. There are two public function codes and I tried in both, nothing happened. If you can post sample of the code integrated with magento core file, that would be nice.

  • Hi @monocat,

    In the file “app/code/core/Mage/Sendfriend/model/Sendfriend.php” have only one “public function send()” function, and in that function, find “foreach($this->_emails as $key => $email) {” this line, and then add my code below the foreach statement.

    It works for me!

  • is it wise to change the core code of Magento ? when you upgrade the Magento, it will be replaced with the new code. I think the better way to add bcc is create a new custom module to handle that based on class Mage_Sendfriend_Model_Sendfriend.

  • Hi there
    does anybody know how to create an entirely new contact form? I want a “request catalogue” form as well as the standard contact form. i have tried replicating it but there are so many files for the contact form it’s ridiculous.

    any help is appreciated!

    thanks

  • still require help if anybody is out there!

  • on my site, the action is blank and the form doesn’t work :(

  • ltmayonnaise Says

    I have the same problem as John… action is blank and the submit fails. Any easy solution?

  • ltmayonnaise Says

    Forgot to mention, I’m using Magento 1.2.1.

  • To John and ltmayonnaise,

    Use single quote instead of double quote. like the following:

    {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}

  • i’ve been struggling it’s been 2 days now, all i wanted to do is just create a copy of the contact us form, in which i want to change the texts then later i want to add some more fields and dropdowns…etc
    i tried every little possible possibility with no success.
    even the last test i’ve done, is just by adding one button to my mainmenu and in the page pointed by that button i added this line
    {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}
    i also tried

    in its layout
    the form come out well but whenever i click on send it just refreshes the page, deltes everything on it, no message is displayed on top, and the mail isn’t sent.
    hope i was clear enough
    any ideas or tutorials on how can i create a copy of the contact us module, or on how to fix this sending problem ?
    thanks very much in advance
    Regards

  • I’m having the same problem geo is, above.

    Any ideas?

  • The contact us form works for me on some browser while on others does not work when i click the submit button it comes back to the same page no confirmation no error message and does not send an email too

  • I tried. I can’t get it to show. I used this exactly…

    {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}

    Not sure if I was suppose to change parts of it to match my template. I’m on Magento 1.1.6

  • I have the same problem as john and ltmayonnaise!

    I have created a page called contact-us and inserted the block into the content of that page like so {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}

    However, when I view the source, the action attribute on my form is blank and when I click submit button the form refreshes, deletes the form data, no messages are displayed and the mail is not sent.

    I went into System/Configuration/General/Contacts and used my own email address to send to, I used custom email 2 as the sender and used a template based on the default template. Contact us is enabled.

    Any one else solved this problem? I am using Magento 1.2.1.2.

  • hi, set up the contact form in a new cms page. it works fine, only the “send” button has no reaction. Where or how can I set this button to send the form?

  • Jonathan Lahijani Says

    I too tried the method described above, but like the comments stated here, it didn’t work (v. 1.3.1). My solution around it was to make a static block called ‘contact_static_block’, which I filled with appropriate content (store hours, directions, etc.).

    Then, in order to insert this static block so that it displayed above the form, I edited the following files:

    /layout/contacts.xml (add this between …)

    contact_static_block

    /template/contacts/form.phtml (add this to the top)
    getChildHtml(‘contact_static_block’) ?>

    You can probably tweak it a bit more to have a little greater control over the positioning of the static block and where it shows up, but this should suffice if you want it at the top, with the form following the static block content.

    Hope this helps!

  • Hi, that’s a good idea.

    But, do you have encounter a problem that, we can not post the contact form?

  • Got it to work on 1.3.1 with single quotes. Double quotes wouldn;t work for some reason.

    {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}

  • Thanks JJ, single quotes worked for me.

  • For those of you who are using magento v.1.3.x, the situation is a little bit different. The completion of the contact form (the actual sending of the email) is not done anymore in the same core template you are picking up by using this code:

    {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}

    This is why you’ll have to change the form action, since posting to itself won’t work and do some modifications to the controller.

    1: include the form (in the cms page) by using the same code:
    {{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}

    2:
    Do some javascript (also in your cms page) to change the action url:

    elem = $(“contactForm”);
    elem.writeAttribute(‘action’, ‘/contacts/index/post’);

    3:
    modify the controller’s redirects: app/code/core/mage/contacts/controllers/IndexController.php

    Rules 108, 115 and 120 contain the locations your visitors will be redirected to after submitting their message.

    Now, your emails will be send to the email adres you configured in your adminpanel (System> Configuration> General> Contacts)

    I don’t know how to display the error-messages yet …

  • this single quote solution to place block is really very helpful.

    Thanks a lot!!

  • Someone please tell me How do i get magento’s new templates on my mail ID…. I want every magento templates on my yahoo ID… How can I get it ?

  • Does anyone have the solution for the form not submitting when used on a CMS page? My form looks great and populates perfectly, but it will not submit – just refreshes the page and deletes the info… I see some others had similar problems – did anyone fix this? Thanks so much!

  • I also see nothing when I insert the block code (single quotes) into a CMS page. Running Magento ver. 1.3.2.3. Help?

  • There’s a forum topic that explains this well here (I used Paul’s solution):

    http://www.magentocommerce.com/boards/viewthread/22807/

  • I also see nothing
    use magento 1.3.2.3

  • When you copy and paste the code above, the quotes will copy funny. You need to replace the quotes you see with freshly-typed double quotes. (Single Quotes will also work).

    Do this, and it will show right up for you.

  • I am beginner in magento1.3 and want to add new page before all product details with checkbox …..how it do..plz help it..

  • I entered the code above as described.
    But when i saved the page it did not work.
    When i looked at the html the cms had added lots of unwanted code – i removed the unwanted code and removed the quotes.
    saved the file and now it works!

  • I did the same thing and just made a new page and pasted your code.
    but when I linked it to main nav and clicked on it, it was a blank page.
    No idea, why it dint work..

  • You shouldn’t just copy n paste.
    After you paste you shoult rewrite the quotes.

  • You guys are so great to put up stuff like this more people just starting out. Thanks so much!

  • thanks for the single quotes solution…

  • Hi,

    Have you had a thought on how you could do this with Fontis Recaptcha extension enabled?

  • Hi, this does not seem to work for Magento 1.4.0.1 – can anyone share how they placed a conact form in a CMS Page?

  • Anyone know how to fix this on 1.4 .. ?

  • Hi, I’m just look around your form but don’t know how to use with my website.

  • @Leke
    I have it working on magento 1.4. Have a look on the link that @mike post above.

    Thank you guys.

  • Jerry Crick Says

    Hi
    I haven’t yet got this working but the real issue is, how do I get the contacts page to adopt the new template I just installed?

    Thanks for your help in advance.

    Jerry

  • thanks eric, your comments worked for :)

  • on my contact us form when i submit it comes up with the following error message: Unable to submit your request. Please, try again later

    anyone know why this is?

  • putting the contact us form in the cms page is a bit complicated since the controller can’t identify what the current form of action is and that’s why the form action has no value at all but this only works fine in other versions of magento but others may cause some problems.
    Instead of doing that, in your menu put this url as the link ‘index.php/contacts/index/’ to the contact us form. If you are using 2 or 3 columns page then just edit the layout xml for contacts default/layout/contacts.xml then replace the 1column to 2columns or 3 columns.phtml (whichever you like to use). You can edit the .phtml of the contact form in default/template/contacts/form.phtml..

    this works very well for me (i think this works to all magento versions) and moreover you don’t have to get concern about the error messages. by the way the error messages will come up if you are working in your localhost, or you didn’t setup the contacts in the backend configuration.

    Hope this will help.

  • Is it possible to keep Magento contact form as is and create another form in a CMS page?

  • [...] Contact Form in Magento – Inchoo // This entry was posted in Magento, Magento 1.4.1.0 CE. Bookmark the permalink. ← Displaying the SKU in Magento [...]

  • Hi bos….
    i flowed your order but no thing happen in my page……
    i just got a blank page…

Leave a Comment

Please wrap all source codes with [code][/code] tags.
Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009