1

I have added a simple subscription form to my Magento site. The form is displaying nicely and the post redirects to my controller without a problem. My issue is actually sending an email. Now I must point out that I'm a bit of a noob with Magento.

My code so far.

$mail = Mage::getModel('core/email');
        $mail->setToName('Your Name');
        $mail->setToEmail('me@gmail.com');
        $mail->setBody('Mail Text / Mail Content');
        $mail->setSubject('Mail Subject');
        $mail->setFromEmail('me@gmail.com');
        $mail->setFromName("Msg to Show on Subject");
        $mail->setType('html');

        try {
            $mail->send();
            Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
            $this->_redirect('');
        }
        catch (Exception $e) {
            Mage::getSingleton('core/session')->addError('Unable to send.');
            $this->_redirect('');
        }

I have been digging through sites and I have pieced this together from what I have found.

Each time the method runs I just get "unable to send"

Is there a good way to debug the mail->send() method as at the moment I have no idea what is failing, just that it is failing.

Thanks in advance

Lyle
  • 11
  • 6
  • you should log the exception: `Mage::logException($e);` so that you know what happens (it will be in MAGENTO_ROOT/var/log/exception.log) – OSdave Oct 01 '13 at 10:44
  • Go to system > configuration > System (group Advanced). Make sure "Disable Email Communications" (Mail sending settings) is set to "No". – JNDPNT Oct 01 '13 at 10:45
  • Hey, yeah thanks I found that in a similar article here http://stackoverflow.com/questions/9393220/magento-not-sending-out-any-mails-how-to-debug The option is set to no already but it does seem to be that check that is stopping the system – Lyle Oct 01 '13 at 13:02

1 Answers1

0

Where is your magento site is hosted..?I mean in local server..or real (online) server..It seems like you were trying to send an email from localhost. You cant send an email from your localhost until you configure email settings in your localserver..

Elavarasan
  • 2,579
  • 2
  • 25
  • 42