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.
Note:You might notice that this is one of our oldest posts. Upon writing we made one error in the code that was never corrected. Now, this post article is updated and we have fully working instructions. Hope this will help.
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” form_action=”/contacts/index/post” template=”contacts/form.phtml”}}
<!– END OF CONTACT FORM –>
Important note: When you copy/paste the code, it is important to know that WordPress saves the quotes in some weird way, so you should replate the pasted quotes and reenter them.
You will notice that we added xml attribute form_action=”/contacts/index/post”. With it we set form action, and your contact form will work properly. Here is how it looks like. Notice the breadcrumbs.
I know that this is not some breakthrough article, but I will certanly create contact CMS page on all of my future Magento projects.
Hope this was helpful. In case you need some help regarding Magento Development, we would be happy to help. Our team of experts would love to review your code and offer insights on improving your store. Our Magento Technical Audit is a great way to start – feel free to contact us!
114 comments
Thank you for your well-explained tutorial.
However, Contact Form 7 shows up in the WP preview, however, the form does not show up on the webpage.
Thank you!
Hi,
Its good post. but there is a minor update in your content
” Important note: When you copy/paste the code, it is important to know that WordPress saves the quotes in some weird way, so you should replate the pasted quotes and reenter them.”
Is this WordPress or Magento?
Really helpful.
is there any way to email all cart product to store admin… just like an inquiry?
The emails are going to the customer and admin, but the admin is not able to reply to the customer.
The “reply-to” field is filled with the admin email.
How to change it ??
Please assist !!
its working in 1.9.2.4 .just copy paste the code as it is
I get a 404 page when the form submits, it takes me to /contacts/index/post
I’ve added the form as per your example code as well.
Hi Max,
I get same issue with you.
Did you fixed this issue?
Is there a way to include captcha in the contact form. I am trying Magento 2.0
“it is important to know that WordPress”… WordPress?
He probably meant that Inchoo.net work on wordpress…
He’s talking about the way that WordPress formats the quotation marks… If you copy and paste code with quotes from WordPress into an editor, it’ll probably throw an error. More info here: https://codex.wordpress.org/Writing_Code_in_Your_Posts
How can I manage the redirect after a message is sent?
By default it redirects to the default and wrong contact page.
Is it possible to use conversion tracking through this method.
For those who find the error /contacts/index/post could not be found, this is because the rendered form html requires an absolute url – if you compare the form action attribute on your CMS page agains the actual contacts page, you will see your CMS action has been rendered as a relative path.
It’s not ideal, but simply edit this:
to this:
Dirty hack – yes.
{{block type=”core/template” name=”contactForm” form_action=”{{store direct_url=”contacts”}}/index/post” template=”contacts/form.phtml”}}
how to set receiver mail id for this custom form
Didn’t worked for me.
Error: The requested URL /contacts/index/post was not found on this server.
It worked! Can you do this for Request for Quote too?
Thanks in advance.
contact form not working in magento
THANK YOU!!!!!
now i’m trying to remove the contact tab on the navigation. any help?
I’ve problem with Contact Us page template still showing old theme. But I want to replace new theme which is enabled in my other pages. except: Register, Login, About Us, Contact Us, My wishlist & My cart page.
Please advice me how can i do visible home page temple to given link pages.
Thanks in advance.
Regards.
I was unable to getting email BUT after following your steps :-It worked for me.
Thank You.
Vishnu
The post is very helpful. We are also developing an Magento extension for better contact form. This will be a super easy way to add contact form to Magento website. http://BetterContactForm.com
Thank you for this lesson. You really saved me. I put the form within a CMS page and its working like a charm.
Pls ck someone may be help this
http://www.magentocommerce.com/magento-connect/extended-contacts-magento-extension.html
ohhooo….its working for me….nice post like it
So glad I came across this will save me alot of time now 🙂
Thanks for your info, works fine
Obrigado! Thanks for your post!
Thanks for this guys, you saved my bacon 🙂
I always come back to this site when I have a new Magento proyect and never thank U 😉
Thx!
I’ve got it working after google it a bit.
My problem was related to the extension Mandrill which changes contact form functionality.
I used:
{{block type=’core/template’ name=’contactForm’ form_action=’/contacts/index/post’ template=’contacts/form.phtml’}}
In my CMS Page to show the form and fix the contact form with the information of this post.
Thanks Inchoo team for such a great contribution to the community given in this blog.
Just a quick thanks for this & all the other articles that you have done for the Magento community.
Best wishes,
Eddie
addon to previous post –
error is same as http://mageme.com/demo/webforms-testimonials-form
I am tried with this way and worked in local but while uploading to live – it is giving me error as Web-form is not active.
I put as
{{block type=”webforms/webforms” name=”webforms” template=”webforms/default.phtml”}}
Thank you. I was trying to figure out why the form was nerver posting and your block for the contact us form actually was the only one that had the info.
{{block type=”core/template” name=”contactForm” form_action=”/contacts/index/post” template=”contacts/form.phtml”}}
This worked 100%.
If you want to have the contact form with in a phtml page then…
1- add the block to the xml you want for example I wanted to add a request form to the product view so, i went to catalog.xml at the and add:
2- just add the getChildHtml:
getChildHtml(‘contactForm’) ?>
So simple i know but took me 3 coffes like all easy things in magento…
It worked for me. Thanks a lot… 🙂
Thanks for this article. It worked for me but after the form is submitted my navigation links have contacts/index inserted between the base URL and the URL Key, presumably because the URL Key is relative. Any idea how fix this?
Worked like a charm indeed. I also changed the URl from /contacts to /contact
thank you
Thank you works a dream in 1.6.
I tried to remove the original link from the footer in my local.xml
but this did not work so I have ended up copying the contacts.xml into my app/theme removing the following section.
Bumping…
Is there anyway to preserve controller in the CMS page? The block is instantiated right and works fina but after the submit from the contacts form it redirects back to home_url/contacts…
I think what everyone realy needs is to stay(after submit) in the CMS page like home_url/my-cms-page..
Gratz.
Does anyone know how to redirect the form to a CMS page without hacking the core?
Thanks for this article, it made me help to create my own contact page with the magento-catact-form. THnx..
Hi I am trying to add that block type to my CMS and it works great for the main website. But does anyone know how to add it to a multi-store set up? if I add that block to my CMS page that is used by more than one of the other “sub”-stores (eg. http://www.MyStore.com/store1/) the form just redirects back to the main store. Any help would be greatly appreciated.
I’ve used this coding, but it does not give a success message stating that the form has been sent.
Can you help?
Please, edit previous comment:
reference name=”content”
block type=”core/template” name=”contactForm” template=”contacts/form.phtml” form_action=”/contacts/index/post”
reference
I’m using the following code and it seems it don’t redirect to the “Thank you” page.
What is wrong?
@Christopher have you tried with some custom code on your category page? you could do an if statement based on the category the client is and show some info or hide it. Don’t think it is the best way but it should work. When the client is on the t-shirt category show t-shirt message and when on the tobacco one show the tobacco message.
Hope it helps.
how do I edit the post php file. I need to make sure users can not post javascript etc through the form
Thanks.
I used like this in my CMS PAGE content and it works fine.
{{block type=”core/template” name=”contactForm” template=”contacts/form.phtml”}}
Dear inchoo team, I like your work, your blog and your tutorials. Keep up the good work! For me your blog is really important and your articles are everything else than ripped off. Some people might think that this is a free support chat, but don’t get confused by that 😉
Thumbs up! Best from Berlin,
Thilo
Christopher,
I’m really sorry, but our developers are extremely busy and didn’t find time to answer a question in the comments on a blog post written last year.
I hope you understand that although we wrote over 500 tutorials / modules / extensions completely free for the community here, we do have obligation to finish work for our clients and feed our families. I hope you don’t mind.
Kind regards,
Marketing Manager, Inchoo
I guess these guys dont respond to inquires or interact with their readers… been back everyday for a month looking for a response on my previous comment on this post any another by a different author yet nothing…. Either that or it is another pointless autoblog with ripped off articles… who knows. Sincerely disappointing though thats for sure.
Dear Christopher,
I can understand why you might get this impression, but let me try to shed some light for you to understand our environment. For 3 years, we are trying to share knowledge via this site and help community in learning. There are now over 100.000 people who visit this site on monthly basis. However, due this reason, some people feel like sharing knowledge is our obligation. Let me be blunt. It is not. We get cca 5-10 inquiries per day currently to provide free support. Theses inquiries are often sent after someone messed up something.
Imagine our workday if we would jump from one side to another trying to help everyone. For free. You don’t need to be economy expert to figure out what would happen. Word would be spread and such free-support inquiries would explode. Inchoo couldn’t pay salaries for employees and they would leave. Quite soon, we would be out of business because nobody would stay.
I am sad you find this blog pointless. It is your opinion and you are entitled to it. However, I can confirm that the articles are not ripped.
Thank you!
We have .htaccess rules, which adds a trailing slash at the end of the url. If you have that, you have to change the form action to /contacts/index/post/! Otherwise email won’t be sent.
Just worked out forgot to add the var to email template
What I really need to do is create a completely New form , not connected to contact us form. I made a duplicate of form.phtml called request.phtml but don’t it is still associated to contact us email template , is it possible to associate away from contact us email template? And how?
I am trying to add 2 extra input fields (Mobile & Fax) by editing form.phtml, they appear when viewing & submitting the form but not in the email?
Have I missed something out?
this is a bit off topic but in previous comments on this thread you mention some altering of the
I been looking all over for some help with this and even though its a bit off topic im hoping you can help me out. Heres a copy and paste of the comment i left on another article on this site but by a different author and the article was a bit old so i wasnt sure if i would hear back from him or if he is active on here still.
———————————————————————
I want to display a notice at the top of certain product pages with additional information regarding what they should select and why. For instance you have lets say a tshirt shop and five of the shirts comes in 4 different materials and you want to display a notice at the top of those 5 product pages that tells you the benefit of choosing one material over the other (this is just example mind you heh) and then you also sell something like hookah tobacco in the same shop which has different levels of nicotine and you want to describe how the different levels of nicotine compare to a regular cigarette or something in that notice box is there a way this can be acheived with your guide?
thanks makes life easier
After submitting the form I’m getting a 404. I think this might be related to the fact that I enabled this option: System – Configuration – General – Web – URL Options – Add storecode to URL’s. The storecode is not added after submitting this form. Do you have any solution for this?
I got it working, here’s my code….
Thank you for these instructions, they have really saved me time.
I have done this in a static block which is placed on a product page that only displays the static block. I changed the code indexcontrol.php so that the contact form redirects back to the correct page. The only issue I have is that the success or failure messages are not being displayed.
I’ve left this line of code in the phtml file:
and the div tag ends up being empty. If I have it going back to the default contact page, the success msg fails. Any ideas on what needs to change? The controller file or the phtml file?
Thanks for your very clear instructions. Can you tell me how I would install a newsletter subscription form into a CMS page? I assume there must be an easy way. Thanks!
I’m trying to have a second “contact” form in addition to the default contact form that Magento supplies. I successfully created this second form by duplicating/editing my form.phtml file and including it onto a CMS page using the code that you’ve supplied in this post.
This becomes problematic in regard to the Email Template that is used when the contact forms are submitted.
Is there any way that my second contact form can be assigned a different Email Template programmatically through either the .phtml file or on the CMS page?
I understand that I can set the default contact form’s Email Template in System –> Configuration, but I trying to change the Email Template that is used for my second “contact form.”
It is very useful but i dont know where the contact form is get submission.how to know that.what is the indication for confirmation .
“User is returned to default Magento ‘Contact’ page and not the page they submitted the form on.”
Yes, in the contacts module (IndexController) you can see this string:
$this->_redirect(‘*/*/’);
So it will redirect after submit on contact page. But. You can extand controller to make it right.
https://inchoo.net/ecommerce/how-to-extend-magento-core-controller/
And make redirect to correct page.
I’m trying to implement it and these are my steps so far, i’ve run into a few problems so if anyone could help it would be appreciated.
1. Copy /app/design/frontend/base/default/template/contacts/ form.phtml to:
/app/design/frontend/default/your_template_name/template/contacts/new_folder/form.phtml
2. Add this code to CMS page:
{{block type=’core/template’ name=’contactForm’ form_action=”/contacts/index/post” template=’contacts/new_folder/form.phtml’}}
This will submit the data, but there are some problems:
– User is returned to default Magento ‘Contact’ page and not the page they submitted the form on.
– The data is received in the format used in the usual ‘Contact’ form (ie same ‘Subject’ and return and reply email address).
– The input from the custom fields is not included in the data delivered to the email address.
Questions:
1. How to make the return page either the page that the form was submitted on or the home page?
2. How to customise the subject title, from and reply address in the email?
3. How to have the custom field input also delivered in the email?
Hello,
Could someone please post a method for adding a new form to a cms page?
Is it just as easy as copying the ‘contacts’ folder to your own template and then referencing that in the cms page?
Thanks!
PS i wasn’t sure if forms had to have different id’s etc?
Still doesn’t work?
Does work for me, i enter:
{{block type=”core/template” name=”contactForm” form_action=”/contacts/index/post” template=”contacts/form.phtml”}}
In the CMS – Manage Pages and nothing….?
Hello Everyone, I would like to let you know that original post was updated now with the working version.
Cheers and enjoy…
Is it possible to keep Magento contact form as is and create another form in a CMS page?
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.
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
Hi, I’m just look around your form but don’t know how to use with my website.
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?
Hi,
Have you had a thought on how you could do this with Fontis Recaptcha extension enabled?
This post explains how to get the form posting correctly:
http://www.casualcommerce.com/2009/03/magento-notes-fix-for-adding-contact-form-in-cms-pages/
thanks for the single quotes solution…
You guys are so great to put up stuff like this more people just starting out. Thanks so much!
You shouldn’t just copy n paste.
After you paste you shoult rewrite the quotes.
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..
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 am beginner in magento1.3 and want to add new page before all product details with checkbox …..how it do..plz help it..
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 also see nothing
use magento 1.3.2.3
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 ?
this single quote solution to place block is really very helpful.
Thanks a lot!!
Thanks JJ, single quotes worked for me.
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’}}
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, 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?
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.
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
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’m having the same problem geo is, above.
Any ideas?
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
To John and ltmayonnaise,
Use single quote instead of double quote. like the following:
{{block type=’core/template’ name=’contactForm’ template=’contacts/form.phtml’}}
Forgot to mention, I’m using Magento 1.2.1.
I have the same problem as John… action is blank and the submit fails. Any easy solution?
still require help if anybody is out there!
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
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 @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!
@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.
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?
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…
Where does the default contact us form send email to? How do you change that?
Cheers,
Chris
System> Configuration> General> Contacts
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
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. 🙂
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?