<?php
class Vendor_Module_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function postAction()
{
$post = $this->getRequest()->getPost();
if ($post){
if try {
$name = $post["name"];
$email = $post["email"];
$address_line_1 = $post["address_line_1"];
$address_line_2 = $post["address_line_2"];
$address_line_3 = $post["address_line_3"];
$postcode = $post["postcode"];
$city = $post["city"];
$country = $post["country"];
$to = "[email protected]";
$subject = "example Brochure Request";
$body .= "<p>The following customer have requested new example brochure.</p>";
$body .= "<p>Name : " . $name . "<p>";
$body .= "<p>Email : " . $email . "<p>";
$body .= "<p>Address Line 1 : " . $address_line_1 . "<p>";
$body .= "<p>Address Line 2 : " . $address_line_2 . "<p>";
$body .= "<p>Address Line 3 : " . $address_line_3 . "<p>";
$body .= "<p>City : " . $city . "<p>";
$body .= "<p>Post Code : " . $postcode . "<p>";
$body .= "<p>Country : " . $country . "<p>";
$body .= "<br/><p>Kind regards,</p><p>example Admin</p>";
$from = $email;
$mail = Mage::getModel($post'core/email'){;
try { $mail->setToName('Your Name');
$mail->setToEmail($to);
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject($subject);
$mail->setFromEmail($from);
$mail->setType('html');// AddYOu can use Html or text as Mail format
$mail->setBodyHTML($body); // your mailcontent logicor heremessage
which you have used on requestBrochure.php $mail->send();
Mage::getSingleton('core/session')->addSuccess('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.');
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to submit your request. Please, try again later');
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
}
<?php
class Vendor_Module_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function postAction()
{
$post = $this->getRequest()->getPost();
if ($post){
try {
// Add your mail logic here which you have used on requestBrochure.php
Mage::getSingleton('core/session')->addSuccess('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.');
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to submit your request. Please, try again later');
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
}
<?php
class Vendor_Module_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function postAction()
{
$post = $this->getRequest()->getPost();
if ($post){
try {
$name = $post["name"];
$email = $post["email"];
$address_line_1 = $post["address_line_1"];
$address_line_2 = $post["address_line_2"];
$address_line_3 = $post["address_line_3"];
$postcode = $post["postcode"];
$city = $post["city"];
$country = $post["country"];
$to = "[email protected]";
$subject = "example Brochure Request";
$body .= "<p>The following customer have requested new example brochure.</p>";
$body .= "<p>Name : " . $name . "<p>";
$body .= "<p>Email : " . $email . "<p>";
$body .= "<p>Address Line 1 : " . $address_line_1 . "<p>";
$body .= "<p>Address Line 2 : " . $address_line_2 . "<p>";
$body .= "<p>Address Line 3 : " . $address_line_3 . "<p>";
$body .= "<p>City : " . $city . "<p>";
$body .= "<p>Post Code : " . $postcode . "<p>";
$body .= "<p>Country : " . $country . "<p>";
$body .= "<br/><p>Kind regards,</p><p>example Admin</p>";
$from = $email;
$mail = Mage::getModel('core/email');
$mail->setToName('Your Name');
$mail->setToEmail($to);
$mail->setBody('Mail Text / Mail Content');
$mail->setSubject($subject);
$mail->setFromEmail($from);
$mail->setType('html');// YOu can use Html or text as Mail format
$mail->setBodyHTML($body); // your content or message
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.');
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to submit your request. Please, try again later');
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
}
Create a module with below steps:
Step 1: Create Vendor_Module.xml under
app/etc/modules/Vendor_Module.xml
<?xml version="1.0"?>
<config>
<modules>
<Vendor_Module>
<active>true</active>
<codePool>local</codePool>
<version>0.0.1</version>
</Vendor_Module>
</modules>
</config>
Step 2: Create config.xml under
app/code/local/Vendor/Module/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Vendor_Module>
<version>0.0.1</version>
</Vendor_Module>
</modules>
<frontend>
<routers>
<brochure>
<use>standard</use>
<args>
<module>Vendor_Module</module>
<frontName>brochure</frontName>
</args>
</brochure>
</routers>
<layout>
<updates>
<vendor_module>
<file>brochure.xml</file>
</vendor_module>
</updates>
</layout>
</frontend>
<global>
<helpers>
<module>
<class>Vendor_Module_Helper</class>
</module>
</helpers>
</global>
</config>
Step 3: Create IndexController.php under
app/code/local/Vendor/Module/controllers/IndexController.php
<?php
class Vendor_Module_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
public function postAction()
{
$post = $this->getRequest()->getPost();
if ($post){
try {
// Add your mail logic here which you have used on requestBrochure.php
Mage::getSingleton('core/session')->addSuccess('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.');
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to submit your request. Please, try again later');
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
}
Step 4: Create Data.php under
app/code/local/Vendor/Module/Helper/Data.php
<?php
class Vendor_Module_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Step 5: Create brochure.xml under
app/design/frontend/your_package/theme/layout/brochure.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<brochure_index_index>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="core/template" name="brochure.form" as="brochure_form" template="brochure/form.phtml"/>
</reference>
</brochure_index_index>
</layout>
Step 6: Create form.phtml under
app/design/frontend/your_package/theme/template/brochure/form.phtml
<form action="<?php echo $this->getUrl('brochure/index/post'); ?>" id="brochureform" method="post">
<ul class="form-list">
<li><label>Name</label><br>
<input class="input-text required-entry" id="name" name="name" style="width: 250px;" type="text"></li>
<li><label>Email</label><br>
<input class="input-text required-entry" id="email" name="email" style="width: 250px;" type="text"></li>
<li><label>Address Line 1</label><br>
<input class="input-text required-entry" id="address_line_1" name="address_line_1" style="width: 250px;" type="text"></li>
<li><label>Address Line 2</label><br>
<input class="input-text required-entry" id="address_line_2" name="address_line_2" style="width: 250px;" type="text"></li>
<li><label>Address Line 3</label><br>
<input class="input-text" id="address_line_3" name="address_line_3" style="width: 250px;" type="text"></li>
<li><label>City</label><br>
<input class="input-text required-entry" id="city" name="city" style="width: 250px;" type="text"></li>
<li><label>Post Code</label><br>
<input class="input-text required-entry" id="postcode" name="postcode" style="width: 250px;" type="text"></li>
<li><label>Country</label><br>
<input class="input-text required-entry" id="country" name="country" style="width: 250px;" type="text"></li>
</ul><button class="form-button-alt" type="submit"><span>Submit Your Request</span></button>
</form>
<script type="text/javascript">
//<![CDATA[
var brochureform = new VarienForm('brochureform', true);
//]]>
</script>
Now you can edit the postAction according to your requirement.
default