1

I have following custom e-mail templates and want to send them to particular customer. enter image description here

My magento function as follows but fails to get relevant e-mail template.

$emailTemplate = Mage::getModel('core/email_template')->loadDefault('Newsletter subscription success new');


        $mail = Mage::getModel('core/email');
        $mail->setToName('John Customer');
        $mail->setToEmail('[email protected]');
        $mail->setBody($emailTemplate);
        $mail->setSubject('The Subject');
        $mail->setFromEmail('[email protected]');
        $mail->setFromName("Your Name");
        $mail->setType('text');// You can use 'html' or 'text'

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

How I get the relevant e-mail template by name?

1 Answer 1

2

Here is the answer for your question.

$emailTemplate = Mage::getModel('core/email_template')->loadByCode('Newsletter subscription success new');

Try with following full code

        $emailTemplate = Mage::getModel('core/email_template')->loadByCode('Newsletter subscription success new');


        $emailTemplateVariables = array(
           'some_custom_variable' => 'Your Variable'
        );

        $processedTemplate = $emailTemplate->getProcessedTemplate($emailTemplateVariables);

        $emailTemplate->setSenderName('Your Name');
        $emailTemplate->setSenderEmail('[email protected]');
        $emailTemplate->setTemplateSubject("e-mail Subject");

        $emailTemplate->send('[email protected]', 'Your Name', $emailTemplateVariables);

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.