How to send custom mail in magento 1.9

In Magento 1.9, you can send custom mail using the Mage_Core_Model_Email_Template class. Here's a step-by-step guide to help you achieve this:

Step 1: Create a new email template

  1. Go to System > Configuration > Advanced > Email > Email Templates.
  2. Click on Add New Template and enter a name for your template (e.g., "Custom Email").
  3. In the Template field, enter the HTML code for your email template.
  4. Click Save to save the template.

Step 2: Create a new email template variable

  1. Go to System > Configuration > Advanced > Email > Email Variables.
  2. Click on Add New Variable and enter a name for your variable (e.g., "customer_name").
  3. In the Variable field, enter the variable name (e.g., {{var customer_name}}).
  4. Click Save to save the variable.

Step 3: Create a custom email sender

  1. Create a new PHP file in the app/code/local directory (e.g., CustomEmail.php).
  2. In this file, create a new class that extends Mage_Core_Model_Email_Template:
    
    <?php

class CustomEmail extends Mage_Core_Model_Email_Template { public function send($templateName, $variables = array()) { // Your custom email logic goes here // For example, you can use the $variables array to populate the email template $template = Mage::getModel('core/email_template')->load($templateName); $template->setVariables($variables); $template->send(); } }

**Step 4: Use the custom email sender**

1. In your Magento module's `config.xml` file, add the following code to register your custom email sender:
```xml
<?xml version="1.0"?>
<config>
    <modules>
        <YourModule>
            <version>1.0.0</version>
        </YourModule>
    </modules>
    <global>
        <models>
            <email>
                <rewrite>
                    <template>CustomEmail</template>
                </rewrite>
            </email>
        </models>
    </global>
</config>

Step 5: Trigger the custom email sender

  1. In your Magento module's code, use the following code to trigger the custom email sender:
    
    <?php

class YourModule_Model_YourModel extends Mage_Core_Model_Abstract { public function sendCustomEmail() { $variables = array('customer_name' => 'John Doe'); $templateName = 'custom_email'; $email = Mage::getModel('email/template'); $email->send($templateName, $variables); } }


In this example, the `sendCustomEmail` method uses the `CustomEmail` class to send a custom email with the `customer_name` variable populated.

That's it! With these steps, you should be able to send custom mail in Magento 1.9 using your own email template and variables.