0

Here is how I'm sending emails from my multi-site magento 1.9.2.4, this function is called by a cron job & working fine to send emails.

Everything is working fine but all of the emails templates (there are different templates for different wesbsites/stores) have store url of admin. I don't know why {{store url=""}}" & "{{config path="web/secure/base_url"}} are returning admin store url instead of the Store Id I'm setting to template

public function sendEmail($templateId, $vars,$storeId ,$name, $email)
{
    try {

        $from_email     = Mage::getStoreConfig('trans_email/ident_general/email',$storeId); //fetch sender email Admin
        $from_name      = Mage::getStoreConfig('trans_email/ident_general/name',$storeId); //fetch sender name Admin
        $emailTemplate  = Mage::getModel('core/email_template');
        $emailTemplate->setStoreId($storeId);
        $emailTemplate->load($templateId);

        $emailTemplate->setSenderName($from_name);
        $emailTemplate->setSenderEmail($from_email);

        foreach ($vars as $key => $value) {
            $emailtemplateVariables[$key]  = $value;
        }

        $result = $emailTemplate->send($email, $name, $emailtemplateVariables);

        Mage::log("Template Id : ".$templateId." send result : ".$result,null,"T-Emails.log");

    } catch(Exception $ex) {
        Mage::log($ex->getMessage(), null,"T-Emails.log");
    }

    return $result;
}

Thanks

1
  • set the template design config $emailTemplate->setDesignConfig(array('area' => 'frontend', 'store' => $storeId));
    – ben.incani
    Aug 29, 2018 at 23:59

1 Answer 1

0

I found the answer for you question :) Maybe it'll be useful for someone.

In your Cron method you have to add

Mage::app()->setCurrentStore($storeId);

I hope I can help someone :)

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.