const XML_PATH_EMAIL_NOTIFICATION_TEMPLATE = 'order_attachments_receive_email_notification';

    public function getEmailAddress() {
    return Mage::getStoreConfig('orderattachments/order_attachments_general/send_email_notification_to')

    static public function sendMail($orderId) {  
    $order = Mage::getModel('orderattachments/orderattachments')->load($orderId);
    $attachmentId = $order->getOrderAttachmentsId();
    $orderId = $order->getOrderId();
    $comment = $order->getComment();
    $attachment = basename($order->getFile());
    try {
        $postObject = new Varien_Object();
        $post['order_id'] = $orderId;
        $post['comment'] = $comment;
        $post['file'] = $attachment;
        $customerEmail = Mage::helper('orderattachments')->getEmailAddress();

        $mailTemplate = Mage::getModel('core/email_template');

        $mailTemplate->setDesignConfig(array('area' => 'frontend'))
                       array('data' => $postObject)
        if(!$mailTemplate->getSentSuccess()) {
            throw new Exception('Not Sent');
    catch (Exception $e) {
        echo "<pre>";
        $errorMessage = $e->getMessage();
        return $errorMessage;




            <order_attachments_receive_email_notification translate="label" module="orderattachments">
                <label>Order Attachments Notification</label>


    <send_email_notification_to translate="label">
                        <label>Email Address</label>

is this correct or not if not correct then tell me what is my mistake?

  • Please review the answer submitted and accept if it solved your problem. Alternately provide further feedback.
    – Moose
    Commented Aug 19, 2015 at 8:24

2 Answers 2


You can call the following mail function from anywhere within your code pool:

$emailTemplate = Mage::getModel('core/email');
$emailTemplate->setFromName('Your Store Name');
$emailTemplate->setToEmail('[email protected]');

Which will use your store's configured emailer to send the email.


The accepted answer shows how to send a simple HTML email. But the code you provided looks like you are trying to use transactional email templates (like the sales module does).

This works as follows

$emailTemplate = Mage::getModel('core/email_template');

    'area' => 'frontend',
    'store' => $storeId

    $variables,             // optional
    $storeId                // optional


  • $storeId is only necessary if you send the email from backend but need to use skin assets or translation from a specific store. If that's not the case, you can also remove the call to setDesignConfig()
  • $template is an email template that you have to define in your modules config.xml:

                <your_custom_email_id translate="label" module="your_module">
                    <label>Your custom eamail</label>

    In this example, $template would be your_custom_email_id and the email template should be located in app/locale/en_US/template/email/your_custom_email.html.

    To make it editable in "Transactional Emails", create a configuration field in system.xml like this:

    <label>Your custom email template</label>

    And assign $template to this configuration value. You should specify the default value in config.xml to be your_custom_email_id

  • $sender can be one of the default store email addresses: "general", "sales" or "support" or as custom sender in the form ['name' => 'John Doe', 'email' => '[email protected]']

  • $recipientEmail is a single email address or an array of email addresses

  • $recipientName is the recipient name or an array of names (same number of elements as $recipientEmail). You can use null to not add a name.
  • $variables is an associative array of variables that can be used in the email template with directives like {{var}} and {{if}}

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.