Technically, this is a duplicate Change the From From magento field to the sender’s email address to the sender , but I put a complete and complete answer here. A simple basic hack is one answer.
I decided not to crack the core files, so I solved this problem by creating a user controller. I read, and it seemed simple enough ... and also no extensions on the market offer goals that I intended to accomplish: 1) have an email and client name on From; 2) simple user input to protect against spam; and 3) a pair of custom fields, 3 of which are actually product attributes.
Files for this:
$ find -type f ./Cycleworks/Cycleworks_ContactExtended.xml ./Cycleworks/ContactExtended/controllers/IndexController.php ./Cycleworks/ContactExtended/Helper/Data.php ./Cycleworks/ContactExtended/etc/config.xml
And now for the files themselves ... The first XML file tells Magento about your custom override.
// copy this to app/etc/modules/ ./Cycleworks/Cycleworks_ContactExtended.xml <?xml version="1.0"?> <config> <modules> <Cycleworks_ContactExtended> <active>true</active> <codePool>local</codePool> </Cycleworks_ContactExtended> </modules> </config>
The remaining files are in app/code/local/ . Below I copied the postAction() function from the source controller and then added my code at the top and then made one change to ->sendTransactional()
./Cycleworks/ContactExtended/controllers/IndexController.php <?php require_once 'Mage/Contacts/controllers/IndexController.php'; class Cycleworks_ContactExtended_IndexController extends Mage_Contacts_IndexController { public function postAction() { $post = $this->getRequest()->getPost(); if ( $post ) { if( stripos( $post["people"],"tires") ===FALSE ){ Mage::getSingleton('customer/session')->addError("Please correctly answer the question to confirm you are human.<br>\"".$this->getRequest()->getPost("people")."\" is not correct."); $this->_redirect('*/*/'); return; } $extras=Array( "bike_year","bike_make","bike_model","bike_model_ext" ); foreach($extras as $field) { if( $post[$field] == "empty" ) $post[$field]= "----"; } $comment = $post['comment']."\nMage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)=\n'".Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER)."'"; $post['comment']= nl2br($comment); $translate = Mage::getSingleton('core/translate'); $translate->setTranslateInline(false); try { ... ... ... $mailTemplate->setDesignConfig(array('area' => 'frontend')) ->setReplyTo($post['email']) ->sendTransactional( Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE), array( 'name'=>$post['name'],'email'=> $post['email'] ),
Nice and empty shell. And yes, all of these have <?php tags but not closing them
./Cycleworks/ContactExtended/Helper/Data.php <?php class Cycleworks_ContactExtended_Helper_Data extends Mage_Core_Helper_Abstract { }
And the XML in the user module:
./Cycleworks/ContactExtended/etc/config.xml <?xml version="1.0"?> <config> <modules> <Cycleworks_ContactExtended> <version>0.0.01</version> </Cycleworks_ContactExtended> </modules> <frontend> <routers> <contacts> <args> <modules> <Cycleworks_ContactExtended before="Mage_Contacts">Cycleworks_ContactExtended</Cycleworks_ContactExtended> </modules> </args> </contacts> </routers> </frontend> <global> <helpers> <contactextended> <class>Cycleworks_ContactExtended_Helper</class> </contactextended> </helpers> </global> </config>
What an all backend. As for the form itself, I added this code in form.phtml below the comment block and above the closing </ul> . For most people, this file is located in app/code/design/frontend/default/default/template/contacts . Since I have a TM template that I bought, I have default/a034/template/contacts
<?php $confirm_people_question="Motorcycles have two of these and rhymes with plires"; <li> <label for="people" class="required"><em>*</em><?php echo $confirm_people_question ?></label> <div class="input-box"> <input name="people" id="people" title="Please confirm you are people" value="" class="required-entry input-text" type="text" /> </div> </li> <?php <li> <div class="ymm"> <label for="bike_year">Year</label><br> <select id="year" name="bike_year"> <option value="empty"></option> <? for( $idx=date("Y"); $idx >= 1985; $idx-- ) echo " <option value=\"$idx\">$idx</option>\n"; ?> </select> </div> <div class="ymm"> <label for="bike_make">Make</label><br> <select id="make" name="bike_make"> <option value="empty"></option> <? foreach( $attributeArray['make'] as $id => $brand ) echo " <option value=\"$brand\">$brand</option>\n"; ?> </select> </div> <div class="ymm"> <label for="bike_model">Model</label><br> <select id="model" name="bike_model"> <option value="empty"></option> <? foreach( $attributeArray['model'] as $id => $model ) echo " <option value=\"$model\">$model</option>\n"; ?> </select> </div> <div class="ymm"> <label for="bike_model_ext">More</label> <div class="input-box"> <input type="text" size="15" value="" id="model_ext" name="bike_model_ext" class="input-text"> </div> </div> </li>
I almost forgot, the final key to the riddle is the mail template in the admin area: System - Transactional Emails . Find your HTML contact template (or create a new one and don’t convert it to plain text), and this is what I have:
<body style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;"> <div style="background:#F6F6F6; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px; margin:0; padding:0;"> <table> <tr><td>Name</td><td>{{var data.name}}</td></tr> <tr><td>E-mail</td><td>{{var data.email}}</td></tr> <tr><td>Telephone</td><td>{{var data.telephone}}</td></tr> </table> <P> <fieldset><legend>Subject: {{var data.subject}}</legend> {{var data.comment}} </fieldset> Bike info: {{var data.bike_year}} {{var data.bike_make}} {{var data.bike_model}} {{var data.bike_model_ext}} </div> </body>
I never thought that I was creating my own module, but I followed the recipes that I found here and elsewhere and put them together. It also behaves correctly when the cap fails. I tried to explore how to enable CC to a client with their own contact, but I could not find anything.
Later I tried to create a custom module to allow an alternative email template for notifications of new orders, but the knowledge that I learned above is not enough .: P So, my knowledge and comfort with Magento may be higher than the “dangerous hack”, but I there is still a long way to go.