Search This Blog

Thursday 26 July 2012

Magento: Create customer and send welcome email programatically

                try {
               
                    $customer = Mage::getModel("customer/customer");
                    $customer->website_id = 1;
                    $customer->store = 1;
                    $customer->entity_type_id     = 1;
                    $customer->group_id = 1;
                    $customer->email = $data['email'];
                   
                    $names = explode(" ", $data['name']);
                    $customer->firstname = $names[0];
                    if(count($names) > 1)
                    {
                        $customer->lastname = $names[1];
                    }
                    else
                    {
                        $customer->lastname = $names[0];
                    }
                   
                    $customer->created_in = "Admin";
                    $customer->created_at =date('Y-m-d H:i:s', time());
                    $customer->updated_at =date('Y-m-d H:i:s', time());
                    $customer->save();
                    //$customer->welcome_email = 1;
                    if ($customer->getWebsiteId())
                    {
                        $storeId = $customer->getSendemailStoreId();
                        $customer->sendNewAccountEmail('registered', '', $storeId);
                       
                     
                        $newPassword = $customer->generatePassword();
                        $customer->changePassword($newPassword);
                        $customer->sendPasswordReminderEmail();
                       
                        $customer->updated_at =date('Y-m-d H:i:s', time());
                        $customer->save();
                    }
                   
                    $data['customer_id'] = $customer->getEntityId();
               
                } catch (Exception $e){
               
                    echo $e->getMessage();
                   
                }

1 comment:

  1. Thanks for the best blog.it was very useful for me.keep sharing such ideas in the future as well.this was actually what i was looking for,and i am glad to came here!
    magento development company in bangalore 

    ReplyDelete