I have a component that I built to make calculations. I would like to allow the person to email their results to themselves. I have tried to create a mail function in the controller of the default.php for the tmpl page, shown here:
public function sendMail () {
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
$sender = array(
$config->get( 'config.mailfrom' ),
$config->get( 'config.fromname' ) );
$mailer->setSender($sender);
$recipient = $calculatorEmailAddress;
$mailer->addRecipient($recipient);
$body = '<div id="emtresults">'
. '<table border="0" width="75%" max-width="750px" cellpadding="1" cellspacing="1" class="table">'
. '<tr class="calcresultslabels">'
. ' <th> </th>'
. ' <th>10foot</th>'
. ' <th>20foot</th>'
. ' <th>Savings</th>'
. ' </tr>'
. ' <tr class="calcresults">'
. ' <th>Materials</th>'
. ' <td align="center"> $ <?php echo round($tenmat1)?></td>'
. ' <td align="center"> $ <?php echo round($twentymat1)?></td>'
. ' <td align="center"> $ <?php echo round($matsavings1)?></td>'
. ' </tr>'
. ' <tr class="calcresults">'
. ' <th>Tax</th>'
. ' <td align="center"><div> $ <?php echo round($tentax1)?></td>'
. ' <td align="center"> $ <?php echo round($twentytax1)?></td>'
. ' <td align="center"> $ <?php echo round($taxsavings1)?></td>'
. ' <tr>'
. ' <tr class="calcresults">'
. ' <th>Hours</th>'
. ' <td align="center"> $ <?php echo round($tenhours1)?></td>'
. ' <td align="center"> $ <?php echo round($twentyhours1)?></td>'
. ' <td align="center"> $ <?php echo round($hourssavings1)?></td>'
. ' </tr>'
. ' <tr class="calcresults">'
. ' <th>Total</th>'
. ' <td align="center"> $ <?php echo round($tentotal1)?></td>'
. ' <td align="center"> $ <?php echo round($twentytotal1)?></td>'
. ' <td align="center"> $ <?php echo round($totalsavings1)?></td>'
. ' </tr>'
. ' </table>'
. ' </div>';
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setSubject('EMT Calculator App Results');
$mailer->setBody($body);
$send = $mailer->Send();
if ( $send !== true ) {
echo 'Error sending email: ' . $send->__toString();
} else {
echo 'Mail sent';
}
}
I then have the action in the /components/component/views/view/tmpl/default.php and code it as here:
<form method='post' action='/index.php?option=com_emtapp&view=calculators&task=sendMail'>
<tr class="calcrow"><td>Email your Results:</td><td align="center"><div> <input type="email" name="calculatorEmailAddress" value=""/></div></td></tr>
<input type="hidden" name="tenmat1" value="<?php echo round($tenmat)?>">
<input type="hidden" name="twentymat1" value="<?php echo round($twentymat)?>">
<input type="hidden" name="matsavings1" value="<?php echo round($matsavings)?>">
<input type="hidden" name="tentax1" value="<?php echo round($matsavings)?>">
<input type="hidden" name="twentytax1" value="<?php echo round($twentytax)?>">
<input type="hidden" name="taxsavings1" value="<?php echo round($taxsavings)?>">
<input type="hidden" name="tenhours1" value="<?php echo round($tenhours)?>">
<input type="hidden" name="twentyhours1" value="<?php echo round($twentyhours)?>">
<input type="hidden" name="hourssavings1" value="<?php echo round($hourssavings)?>">
<input type="hidden" name="tentotal1" value="<?php echo round($tentotal)?>">
<input type="hidden" name="twentytotal1" value="<?php echo round($twentytotal)?>">
<input type="hidden" name="totalsavings1" value="<?php echo round($totalsavings)?>">
<input type='submit' value='Email Your Results'/>
</form>
However it will not send any email. Does any one have any suggestion as to what I am doing wrong here?
var_dump($recipient);
, what gets displayed?