I cannot send the email by clicking on the button 'email me'.It is redirecting and showing an empty page.Please anyone help me
my code form.phtml
<div>
<b> Hello <?php echo $_POST["name"]; ?>!</b><br>
<b>Email :</b> <?php echo $_POST["email"]; ?>.<br>
<b>Gender :</b> <?php echo $_POST["gender"]; ?>.<br>
<b>Birthday :</b>
<?php
$day = $_POST['day'];
$month = $_POST['month'];
$year = $_POST['year'];
$date = $day."-".$month."-".$year;
$my_date = date('d-m-Y', strtotime($date));
echo $my_date;
?>
</div>
<div>
<form method="post" action="<?php echo $this->getPostActionUrl()?>" id="form-validate">
<table border="1" style="width:100%">
<tr>
<th id= "sno" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class="bg-color" width="5%">S.No</th>
<th id= "vaccine" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class="bg-color center" width="32%">Vaccine</th>
<th id="decsription" style="font-family: sans-serif; font-size: 100%; font-weight: bold;">Description</th>
<th id="duedate" style="font-family: sans-serif; font-size: 100%; font-weight: bold;" class ="bg-color" width="15%">Due Date</th>
</tr>
<tr>
<td>1</td>
<td><a href="http://www.labwise.in/devel/hepatitis-b/" style="color: rgb(0,255,0)"><font color="#0000FF">Hepatitis B</font></a>
</td>
<td>
<b><span> At birth: </span></b><br></br>
<span>For infants born to hepatitis B surface antigen (HBsAg)-positive mothers, administer HepB vaccine and 0.5 mL of hepatitis B immune globulin (HBIG) within 12 hours of birth. These infants should be tested for HBsAg and antibody to HBsAg (anti-HBs) 1 to 2 months after completion of the HepB series at age 9 through 18 months (preferably at the next well-child visit).</span>
</td>
<td>
<div id="duedtdiv">
<div class="input-box dob" id="duedtdiv">
<?php
$date=date_create("now");
$bdate=date_create($my_date);
//echo date_format($dueDate,'d-m-Y');
if($date >= $bdate)
{
$dueDate=$bdate->modify('+6 week');
echo date_format($dueDate,"d-m-Y");
}
else
{
$bdate->modify('+2 week');
echo date_format($bdate,'d-m-Y');
}
?>
</div>
</div>
</td>
</tr>
</table>
</form>
<button type="submit" title="<?php echo $this->__('Save Form') ?>" class="button"><span><span><?php echo $this->__('Save Form') ?></span></span> </button></div>
</div>
<div>
<button type="submit" title="<?php echo Mage::helper('vaccination')->__('Email Me') ?>" class="button"><span><span><?php echo Mage::helper('vaccination')->__('Email Me')?></span></span> </button>
</div>
<script type="text/javascript">
//<![CDATA[
var dataForm = new VarienForm('form-validate', true);
//]]>
</script>
IndexController.php
<?php
class Labwise_Vaccination_IndexController extends Mage_Core_Controller_Front_Action
{
const XML_PATH_EMAIL_RECIPIENT = 'contacts/customemail/recipient_email';
const XML_PATH_EMAIL_SENDER = 'contacts/customemail/sender_email_identity';
const XML_PATH_EMAIL_TEMPLATE = 'contacts/customemail/email_template';
const XML_PATH_ENABLED = 'contacts/vaccination/enabled';
public function preDispatch()
{
parent::preDispatch();
if( !Mage::getStoreConfigFlag(self::XML_PATH_ENABLED) ) {
$this->norouteAction();
}
}
public function indexAction()
{
$this->loadLayout();
$this->getLayout()->getBlock('vaccinationform')
->setFormAction( Mage::getUrl('*/*/send') );
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->renderLayout();
}
public function sendAction()
{
$post = $this->getRequest()->getPost();
if ( $post ) {
$translate = Mage::getSingleton('core/translate');
$translate->setTranslateInline(false);
try {
$postObject = new Varien_Object();
$postObject->setData($post);
$error = false;
if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
$error = true;
}
if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
$error = true;
}
if (Zend_Validate::is(trim($post['hideit']), 'NotEmpty')) {
$error = true;
}
if ($error) {
throw new Exception();
}
Zend_Debug::dump($postObject);
die();
$mailTemplate = Mage::getModel('core/email_template');
$mailTemplate->setDesignConfig(array('area' => 'frontend'))
->setReplyTo($post['email'])
->sendTransactional(
Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
null,
array('data' => $postObject)
);
if (!$mailTemplate->getSentSuccess()) {
throw new Exception();
}
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addSuccess(Mage::helper('vaccination')->__('Thanks for your enquiry. We will be in touch shortly!'));
$this->_redirect('*/*/');
return;
} catch (Exception $e) {
$translate->setTranslateInline(true);
Mage::getSingleton('customer/session')->addError(Mage::helper('vaccination')->__('Sorry, we were unable to submit your enquiry.'));
$this->_redirect('*/*/');
return;
}
} else {
$this->_redirect('*/*/');
}
}
}
?>
email template:
<?php
$installer = $this;
$installer->startSetup();
$installer->run("
INSERT INTO {$this->getTable('core_email_template')} (`template_code`, `template_text`, `template_type`, `template_subject`, `template_sender_name`, `template_sender_email`, `added_at`, `modified_at`) VALUES
('Vaccination', 'Child Name: {{var data.name}}\r\nE-mail: {{var data.email}}\r\nMobile Number: {{var data.mobile}}', 1, 'Vaccination', NULL, NULL, NOW(), NOW());
");
$installer->endSetup();