Magento – How to send set password email

customeremailmagento-1.9namepassword

I want to send a "set password" email to users.

I made a script where there is an option like "user register by email id" and other details. We review their detail and activate them. When the user is activated, a mail is sent to them to set the password for their account.

I'm stuck with part of sending set password email.

Best Answer

Take a look at Magento Migrate customers with no password.

$customer = Mage::getModel('customer/customer');

$password = '123456';
$email = 'testuser@test.com';

$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($email);

if($customer->getId()) { // if customer does not already exists, by email

    $newPassword = $customer->generatePassword(); // generate a new password
    $customer->changePassword($newPassword); // set it
    $customer->save();    
}

Assuming that you want to use the default magento password template then take a look at app/code/core/Mage/Adminhtml/controllers/CustomerController.php

// Send welcome email
if ($customer->getWebsiteId() && (isset($data['account']['sendemail']) || $sendPassToEmail)) {
    $storeId = $customer->getSendemailStoreId();
    if ($isNewCustomer) {
        $customer->sendNewAccountEmail('registered', '', $storeId);
    } elseif ((!$customer->getConfirmation())) {
    // Confirm not confirmed customer
            $customer->sendNewAccountEmail('confirmed', '', $storeId);
    }
}