Creating email template in magento

The templates used for transactional email are formatted with HTML and CSS, and may be simply altered. additionally, you’ll be able to customize the templates by adding variables and frontend apps. so lets discuss about creating email template in magento

Many of the default email templates contain placeholder info that ought to be modified before any transactional email messages are sent to customers. once the template is prepared to be used, ensure to update your system configuration, that the updated template are used rather than the previous version.

Step 1: Choose a Previously created Template

  • On the Admin menu, select System > Templates > Transactional Emails.

Creating email template in magento

  • Click the Add New Template button.
  • In the Load default template section, choose the default Template you want to use as a starting point. Then, click the Load Template button.
  • If necessary, set the Locale to the store language.
  • Click the Load Template button.

Creating email template in magento1

Step 2: Altering the Content

  • In the Template Information section, do the following:
    • Enter a Template Name for the new email template.
    • In the Template Subject field, type the text to appear in the Subject header of the message.
    • Complete the Template Content, according to your needs.
  • (Optional) To insert a variable, do the following:
    • Position the cursor in the text where you want the variable to appear. Then, click the Insert Variable button.
    • In the list of available variables, select the one you want to insert into the template.
  • (Optional) To insert a frontend app, do the following:
    • Position the cursor in the text where you want the frontend app to appear. Then, click the Frontend App button.
    • In the list of available frontend apps, select the one you want to insert into the template.
    • When complete, click the Save Template button.
    • After completing the template, make sure to Preview the message before associating it with a transactional email message that is sent to customers.

Step 3: Save the Configuration

Before the template can be used, the configuration must be updated with the name of the new template.

Hope this helps you in creating email template in magento

Send email using email template in magento manually

Using the default mail sending and template functionality of magento we can also send our custom email to the customers using the created email templates in the magento admin
so to recaps we are discussing about the send email using email template in magento manually
Here is the code snippets to do so

$customer = Mage::getSingleton('customer/session')->getCustomer(); //suppose the customer whose data to be fetched is 2 
                if(!empty($customer)) 
                { 
                    $mailTemplate = Mage::getModel('core/email_template'); 
                    /* @var $mailTemplate Mage_Core_Model_Email_Template */ 
              
                    $translate  = Mage::getSingleton('core/translate'); 
                      
                    $templateId = 2; //template for sending customer data 
                    $template_collection =  $mailTemplate->load($templateId);                                
                    $template_data = $template_collection->getData(); 
                    if(!empty($template_data)) 
                    { 
                        $templateId = $template_data['template_id']; 
                        $mailSubject = $template_data['template_subject'];                          
                          
                        //fetch sender data from Adminend > System > Configuration > Store Email Addresses > General Contact 
                        $from_email = Mage::getStoreConfig('trans_email/ident_general/email'); //fetch sender email 
                        $from_name = Mage::getStoreConfig('trans_email/ident_general/name'); //fetch sender name 
                  
                        $sender = array('name'  => $from_name, 
                                        'email' => $from_email);                                
 

                        $vars = array('variable'=>'value' ); //for replacing the variables in email with data                   
                        /*This is optional*/ 
                        $storeId = Mage::app()->getStore()->getId(); 
                        $model = $mailTemplate->setReplyTo($sender['email'])->setTemplateSubject($mailSubject); 
                        $email = $customer->getEmail(); 
						//  $email = 'navaneeth008@gmail.com'; 
                        $name = $customer->getName();                                            
                        $model->sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);                     
                        if (!$mailTemplate->getSentSuccess()) { 
                                throw new Exception(); 
                        } 
                        $translate->setTranslateInline(true); 
                    } 
                } 

we have specified and

$templateId = 2; //template for sending customer data 

This is the template id we created in the magento admin for our purpose

and

$vars = array('variable'=>'value' ); //for replacing the variables in email with data  

This is the array of variables used to replace the content in the email ie if the email template has the value like
{variable}
its replaced by the “value” field we are passing through the array

To be concluded we discussed here about how we can send email using email template in magento manually with ease.
Ping me if you have any doubts

Activate wordpress plugin php code

Being a developer some times when developing wordpress plugin what if we don’t have the admin access to activate the plugin. So in this post we are discussing about how we can activate wordpress plugin php code
we need to run an function named do_activate_plugin
so place the custom function inside the themes functions.php
and run the website
Here is the code for the function

function do_activate_plugin( $plugin ) {
    $current = get_option( 'active_plugins' );
    $plugin = plugin_basename( trim( $plugin ) );

    if ( !in_array( $plugin, $current ) ) {
        $current[] = $plugin;
        sort( $current );
        do_action( 'activate_plugin', trim( $plugin ) );
        update_option( 'active_plugins', $current );
        do_action( 'activate_' . trim( $plugin ) );
        do_action( 'activated_plugin', trim( $plugin) );
    }

    return null;
}
do_activate_plugin( 'categorize/categorize.php' );

The parameter passed in the function is the pluginfolder/pluginfile

Hope this will help you you activate wordpress plugin php code

Remove rows with multiple duplicate columns

Some times we need to remove rows with multiple duplicate columns as shown in the table below,See the last two rows with same values.

ID           college   courses 
183             24        102         
151             24         52           
155             24         66           
179             24         66           

With the help of temporary table we can remove rows and here is the query to remove the rows

CREATE TABLE temp_table AS (SELECT * FROM table);
DELETE FROM table WHERE ID NOT IN 
(SELECT ID FROM (SELECT * FROM temp_table ORDER BY ID DESC) 
as temp_table GROUP BY college, courses);
DROP TABLE temp_table ;

Hope it helps to remove rows with multiple duplicate columns