0

I made a custom form using instructions found at Inchoo. I've created the form and it's appearing properly but the mails are not sending at all. I get an error 'Unable to Send email' which comes from the catch part of the code. Nothing in the system.log or exceptions.log files to give me a clue.

The form has an action of domain.com/postajob/index/sendemail/ and my IndexController.php file looks like this

<?php
class BWD_JobForm_IndexController extends Mage_Core_Controller_Front_Action
{
public function sendemailAction()
{
    //Fetch submited params
    $params = $this->getRequest()->getParams();
    $from_email = Mage::getStoreConfig('trans_email/ident_general/email');
    $from_name = Mage::getStoreConfig('trans_email/ident_general/name');

    $mail = new Zend_Mail();
    $mail->setBodyText($params['role']);
    $mail->setFrom($from_email, $from_name);
    $mail->addTo($params['email'], $params['name']);
    $mail->setSubject('Test Post a Job Module for Magento');
    try {
        $mail->send();
    }
    catch(Exception $ex) {
        Mage::getSingleton('core/session')->addError($ex->getMessage());
    }

    //Redirect back to index action of (this) inchoo-simplecontact controller
    $this->_redirect('thanks/');
}
}
?>

I've also tried methods mentioned here and here but none of them work. For the record, mail sending is enabled in the configuration.

4
  • @TejabhagavanKollepara This is custom email. Commented Oct 14, 2016 at 9:25
  • check this magento.stackexchange.com/questions/110326/… Commented Oct 14, 2016 at 9:25
  • I've set the cron times to 1 minute and I've been trying it for hours now
    – Whip
    Commented Oct 14, 2016 at 9:28
  • Is it possible to get a more detailed description from exception rather than just 'Unable to send'?
    – Whip
    Commented Oct 14, 2016 at 9:35

1 Answer 1

0

you can try below code for email this is always working for me.

$mail = Mage::getModel('core/email')
->setToName($senderName)
->setToEmail($customerEmail)
->setBody($YourMSG)
->setSubject('Subject :')
->setFromEmail($senderEmail)
->setFromName($senderName)
->setType('html');

$mail->send(

And also you can try below code

$emailTemplate  = Mage::getModel('core/email_template');
$emailTemplate->setSenderName('Name');
$emailTemplate->setSenderEmail('[email protected]');
$emailTemplate->setTemplateSubject('Subject');
$emailTemplate->send('[email protected]','ReciverName',$data);
4
  • Can you expand your answer for newbies? What's $Data for instance?
    – Whip
    Commented Oct 14, 2016 at 9:30
  • your data that you want to send with mail Commented Oct 14, 2016 at 9:40
  • Then what's 'msg'?
    – Whip
    Commented Oct 14, 2016 at 9:53
  • check updated answer Commented Oct 14, 2016 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.