How to Send Email Using Magento

magento-1.8

I have created a form with some input fields in Magento. But when I click submit, Magento will not send the email.

How can I send a basic email in Magento?

Best Answer

simple function to send the email in magento

<?php
    public function sendMailAction() 
    {
        $html="
        put your html content here
        blah blah

        ";
        $mail = Mage::getModel('core/email');
        $mail->setToName('Your Name');
        $mail->setToEmail('Youe Email');
        $mail->setBody('Mail Text / Mail Content');
        $mail->setSubject('Mail Subject');
        $mail->setFromEmail('Sender Mail Id');
        $mail->setFromName("Msg to Show on Subject");
        $mail->setType('html');// You can use Html or text as Mail format
        $mail->setBodyHTML($html);  // your content or message

        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('');
        }
    }
?>

Reference

Related Topic