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('exa@gmail.com');
        $mail->setBody($emailTemplate);
        $mail->setSubject('The Subject');
        $mail->setFromEmail('my@my.com');
        $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

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('sender@somemail.com');
        $emailTemplate->setTemplateSubject("e-mail Subject");

        $emailTemplate->send('receiver@somemail.com', 'Your Name', $emailTemplateVariables);

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.