Joomla 3.2 компонентный почтовик
У меня есть компонент, который я построил для расчетов. Я хотел бы позволить человеку посылать свои результаты по электронной почте себе. Я попытался создать почтовую функцию в контроллере default.php для страницы tmpl, показанной здесь:
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';
}
}
Затем у меня есть действие в /components/component/views/view/tmpl/default.php и код, как здесь:
<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>
Однако он не будет отправлять по электронной почте. Есть ли у кого-нибудь какие-либо предположения относительно того, что я здесь делаю неправильно?