1

I need to pass Customer Full Name and Order # dynamically to mail, but not receiving in actual Email.

Controller

$templateId = 17;
$emailTemplate = Mage::getModel('core/email_template')->load($templateId);

$processedTemplate = $emailTemplate->getProcessedTemplate();

$mail = Mage::getModel('core/email');
$mail->setToName($customer->getId());

$email_template_variables = array(
   'customer_name' => $fullName,
   'order_id' => $orderID
);

$mail->setTemplateParam($email_template_variables);
$mail->setToEmail($customer->getEmail());
$mail->setBody($processedTemplate);
$mail->setSubject($mailSubject);
$mail->setFromEmail($from_email);
$mail->setFromName($from_name);
$mail->setType('Html');

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

Accessing those variables by

{{var customer_name}} and {{var order_id}}

It is empty. No Value.

4

You have to set the variable to that template so that you can get the value in email template. Try the below code

$mail = Mage::getModel('core/email');
$mail->setToName($customer->getId());

$email_template_variables = array(
   'customer_name' => $fullName,
   'order_id' => $orderID
);

$processedTemplate = $emailTemplate->getProcessedTemplate($email_template_variables);
| improve this answer | |
3

no need to use core/email you can do with core/email_template

here i can suggest you to use like this

 $emailTemplate = Mage::getModel('core/email_template')->load($this->_email_template); 

$vars = array('customer_name' => $fullName,
              'order_id' => $orderID);

 $emailTemplate->getProcessedTemplate($vars);
 $from = $this->getFromMail($this->_identity);
 $emailTemplate->setSenderEmail($from['email']);
 $emailTemplate->setSenderName($from['name']);
 $billingAddress = $order->getBillingAddress();
 $success_flag = $emailTemplate->send($order->getCustomerEmail(), $billingAddress->getFirstname(), $vars);

hope this will work for you.

| improve this answer | |
2

You need to changes in template id and add varibles

Go to System->transnational email and open your template whose id is 17 as you defined in your controller and add these below variable where you want to show in your mail template.

$email_template_variables = array(
       'customer_name' => $fullName,
       'order_id' => $orderID
 )

{{var customer_name}} and {{var order_id}}

| improve this answer | |

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.