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.

  • @TejabhagavanKollepara This is custom email. – Qaisar Satti Oct 14 '16 at 9:25
  • I've set the cron times to 1 minute and I've been trying it for hours now – VeeK Oct 14 '16 at 9:28
  • Is it possible to get a more detailed description from exception rather than just 'Unable to send'? – VeeK Oct 14 '16 at 9:35
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@provider.com');
$emailTemplate->setTemplateSubject('Subject');
$emailTemplate->send('Email@provider.com','ReciverName',$data);
  • Can you expand your answer for newbies? What's $Data for instance? – VeeK Oct 14 '16 at 9:30
  • your data that you want to send with mail – Murtuza Zabuawala Oct 14 '16 at 9:40
  • Then what's 'msg'? – VeeK Oct 14 '16 at 9:53
  • check updated answer – Murtuza Zabuawala Oct 14 '16 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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