Send order email to third party in Magento

<?php

// Set all required params and send emails

$storeId = 1;
$order = Mage::getModel(‘sales/order’)->load(2);
echo $templateId = Mage::getStoreConfig(‘sales_email/order/template’, $storeId);
$paymentBlock = Mage::helper(‘payment’)->getInfoBlock($order->getPayment())->setIsSecureMode(true);
$paymentBlock->getMethod()->setStore($storeId);
$paymentBlockHtml = $paymentBlock->toHtml();

// Sent mail to admin.

$orderArray = array(
‘order’ => $order,
‘billing’ => $order->getBillingAddress() ,
‘payment_html’ => $paymentBlockHtml
);
$adminTemplate = Mage::getModel(‘core/email_template’)->load($templateId);
$processedTemplate = $adminTemplate->getProcessedTemplate($orderArray);

// echo ‘<pre>’; print_r($adminTemplate->getData()); die(‘EXIT’);

$mail = Mage::getModel(‘core/email’)->setToName(‘BMMM’)->setToEmail(‘testtommail@gmail.com’)->setBody($processedTemplate)->setSubject(“Test Subject!!!”)->setFromEmail(“test@frommail.com”)->setFromName(“Test from name”)->setType(‘html’);
$mail->send();

Leave a comment